Docsity

Initializing Max Heap - Algorithms and Applications in Java - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download Initializing Max Heap - Algorithms and Applications in Java - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

input array = [-, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

Start at rightmost array position that has a child.

Index is n/2.

Find a home for 2.

Done, move to next lower array position.

Find home for 1.

Find home for 1.

Done.

Time Complexity

Height of heap = h.

Number of subtrees with root at level j is <= 2

j-

Time for each subtree is O(h-j+1).

Leftist Trees

Linked binary tree.

Can do everything a heap can do and in the

same asymptotic complexity.

Can meld two leftist tree priority queues in

O(log n) time.

Extended Binary Trees

Start with any binary tree and add an

external node wherever there is an

empty subtree.

Result is an extended binary tree.