Heap pattern Flashcards
1
Q
What is a min heap? What is a max heap?
A
It’s a binary tree with two important features
1. complete tree
- Every node is less than both children
root is the min value
A max heap is the same as the above except the opposite ordering where the root is the max node
2
Q
What are the typical functions for a heap?
A
top - similar to peak where the current root is returned
push - inserts a new value and after that we still have the two properties preserved.
pop - Removes the min value and after that we still have two properties preserved.
3
Q
A