A crossover between Floyd’s and Williams’s methods for constructing a heap is a method in which an empty position occupied by an element is moved down to the bottom of the tree and then the element is moved up the tree, as in Williams’s method, from the position that was just moved down. A pseudocode of this function is as follows:
i = n/2-1; // position of the last parent in the array of n elements;while (i >= 0) // Floyd’s phase: tmp = data[i]; consider element data[i] empty and move it down to the bottom swapping it every time with larger child; put tmp in the leaf at which this process ended; // Williams’s phase: while tmp is not the root data[i] of the current tree and it is larger than its parent swap tmp with its parent; i--; // go to the preceding parent;
It has been shown that this algorithm requires 1.65n comparisons in the average case (McDiarmid and Reed 1989). Show changes in the array [2 8 6 1 10 15 3 12 11] during execution of the algorithm. What is the worst case?
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.