Suppose that you have a hole at node x the normal perc down


Question: Suppose that you have a hole at node X. The normal perc Down routine is to compare X's children and then move the child up to X if it is larger (in the case of a max heap) than the element to be placed, thereby pushing the hole down. Stop when placing the new element in the hole is safe. Consider the following alternative strategy for perc Down. Move elements up and the hole down as far as possible without testing whether the new cell can be inserted. These actions would place the new cell in a leaf and probably violate heap order. To fix the heap order, percolate the new cell up in the normal manner. The expectation is that the percolation up will be only one or two levels on average. Write a routine to include this idea. Compare the running time with that of a standard implementation of heapsort.

Solution Preview :

Prepared by a verified Expert
Data Structure & Algorithms: Suppose that you have a hole at node x the normal perc down
Reference No:- TGS02462771

Now Priced at $20 (50% Discount)

Recommended (99%)

Rated (4.3/5)