Remember Me Forgot your Password?

Forum: Electrical & Computer Engineering :: Data Structures & Algorithms :: Binary trees  New Topic
Problem #17 Reply
Author Message
nak31 Problem #17 Mon 20 Apr 2009 8:15:00 PM
Student
Joined Tues 31 Mar 2009
Posts 511
Edited by djazzleb on Jun 18 2009 11:31AM UTC

30
26
7
15
11
38
29
40
35
16
9

Redraw the heap on the right after calling RemoveMax 2 times.

Assume that siftdown is called after each call to

RemoveMax.


Attachment
Student Rating4/5
Student Rating5/5
nak31 Mon 20 Apr 2009 8:17:00 PM
Student
Joined Tues 31 Mar 2009
Posts 511

Calling RemoveMax the first time:
First we replace the maximum 40 with the last element and delete the last element.

Then we siftdown our new maximum which is 7. In sifting down if the largest of a node’s children is greater than the mother node, we swap it with the node. As a result 7 will be swapped with 38, then it will be swapped with 35 and after that it will be swapped with 16. 

Similarly we call RemoveMax for the second time and after fully executing it the heap becomes the last figure.

 


Attachment
Student Rating4/5
Student Rating3/5
1
© Copyright SolveMyProblem.Net 2010