Part 9 heap
Part 9 heap
Part 9 heap
Part 9: Heaps
82 70 51 63 55 37 10 43 27 30 34 95
82 70 51 63 55 95 10 43 27 30 34 37
82 70 95 63 55 51 10 43 27 30 34 37
95 70 82 63 55 51 10 43 27 30 34 37
95 82 51 63 70 37 10 43 27 55 34 30
30 82 51 63 70 37 10 43 27 55 34
82 30 51 63 70 37 10 43 27 55 34
82 70 51 63 30 37 10 43 27 55 34
82 70 51 63 55 37 10 43 27 30 34
7 Data Structures and Algorithms Part 9
Efficiency of Heap Operations
For a heap with a substantial number of items, the trickle-up and trickle-down
algorithms are the most time-consuming part of the operations we’ve seen.
These algorithms spend time in a loop, repeatedly moving nodes up or down
along a path.
The trickleUp() method has only one major operation in its loop: comparing
the key of the new node with the node at the current location.
The trickleDown() method needs two comparisons: one to find the largest
child and a second to compare this child with the “last” node.
They must both copy a node from top to bottom or bottom to top to
complete the operation.
22
20 18
14 11 10 15
9 13 8 6