Heaps Flashcards
1
Q
Heap definition
A
A specialized tree with two properties:
Structure property: Is a complete binary tree. No empty nodes except the right side of the last row.
Order property: The entire subtree under a node is all less/more than the node.
2
Q
Time complexity
Create?
Push?
Pop?
A
O(n) to heapify
O(logn) to push/pop
3
Q
Algorithm to push
A
Insert at the end of the array, then percolate up/down by comparing element to its parent and swapping if necessary, recursively.
4
Q
Algorithm to pop
A
Copy the last element in the array to the root, then percolate it down to its proper place.