Question

Show that the worst-case runtime of the Algorithm Heapify is on an array of length n...

Show that the worst-case runtime of the Algorithm Heapify is on an array of length n in Ω(log(n)).
Note: Construct a heap A with n nodes and show that heapify is called recursively accordingly.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Let's say we are performing MAX-HEAPIFY. I am providing the algorithm here.

MAX-HEAPIFY( A, i) //where A is array of length n and i is the index of root

{

l = 2i;

r = 2i+1;

if( l <= A.heap-size && A[ l ] > A[ i ])

largest = l ;

else largest = i;

  if( r <= A.heap-size && A[ r ] > A[ largest ])

largest = r;

if ( largest != i)

exchange A[ i ] with A[ largest]

MAX-HEAPIFY(A, largest); //Recursive call to MAX-HEAPIFY

}

//Building max-heap

BUILD-MAX-HEAP(A)    //where A is array of length n and i is the index of root

{

A.heap_size = A.length

for( i = |_A.length/2_| down to 1)

MAX-HEAPIFY(A, i); //Calling MAX-HEAPIFY FUNCTION

}

Explanation on worst-case runtime of the Algorithm Heapify is on an array of length n in Ω(log(n)).

MAX-HEAPIFY works when a left subtree is heap and also the right subtree is heap but their parent is not following the heap rule.

Now we know that the height of a tree is log(n), where n is the number of nodes.MAX-HEAPIFY, when applied, will result in O(2*logn) which inturn will result in Ω(log(n)). Since 2 is a constant and can be neglected in time-complexity.

Add a comment
Know the answer?
Add Answer to:
Show that the worst-case runtime of the Algorithm Heapify is on an array of length n...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT