void build (int[] elts, int N); // The "magic" build operation which constructs a heap in O(N) time // the first parameter is an array that contains all the elements that // will go into the heap; the second parameter tells how many elements // there are (so that the array "elts" can be larger than the number // of elements in it... we do not depend on elts.length to determine // the size of heap we build. // // The method works as follows: // first: the heap that is doing the build will do a clear() // and it will lose any elements already in that heap // second: load the elements in parameter "elts" into the heap // array directly ( a O(N) copying action ) // third: perform the "bubble down" operations that a build // requires on the heap array // // When testing look to find a sequence of elements that let you // get two different heap structure when you // 1) create a heap from N separate inserts // 2) do this build method // // Here is one such sequence: 101, 37, 26, 19, 15, 12, 9, 2, 3, 5 // // Here is another (from your class PPT): 6, 12, 9, 4, 5, 3 // // Example: If you call insert on each element one-by-one // for the sequence 6, 12, 9, 4, 5, 3, you obtain the following min-heap: // 3, 5, 4, 12, 6, 9 // However, build() will produce the following min-heap: // 3, 4, 6, 12, 5, 9 } In java language all info under method please and thank you! simply builds a min heap thats all
void build (int[] elts, int N);
// The "magic" build operation which constructs a heap in O(N) time
// the first parameter is an array that contains all the elements that
// will go into the heap; the second parameter tells how many elements
// there are (so that the array "elts" can be larger than the number
// of elements in it... we do not depend on elts.length to determine
// the size of heap we build.
//
// The method works as follows:
// first: the heap that is doing the build will do a clear()
// and it will lose any elements already in that heap
// second: load the elements in parameter "elts" into the heap
// array directly ( a O(N) copying action )
// third: perform the "bubble down" operations that a build
// requires on the heap array
//
// When testing look to find a sequence of elements that let you
// get two different heap structure when you
// 1) create a heap from N separate inserts
// 2) do this build method
//
// Here is one such sequence: 101, 37, 26, 19, 15, 12, 9, 2, 3, 5
//
// Here is another (from your class PPT): 6, 12, 9, 4, 5, 3
//
// Example: If you call insert on each element one-by-one
// for the sequence 6, 12, 9, 4, 5, 3, you obtain the following min-heap:
// 3, 5, 4, 12, 6, 9
// However, build() will produce the following min-heap:
// 3, 4, 6, 12, 5, 9
}
In java language
all info under method
please and thank you!
simply builds a min heap thats all
Trending now
This is a popular solution!
Step by step
Solved in 2 steps