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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Time complexity
Create?
Push?
Pop?

A

O(n) to heapify
O(logn) to push/pop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Algorithm to pop

A

Copy the last element in the array to the root, then percolate it down to its proper place.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly