Binary Heaps & Priority Queues Flashcards
What are the API methods for a binary heap
Push(v)
Min()
Pop()
Size()
Empty()
Clear()
Define what a heap is
A complete binary tree, where every level will be full, except for the last, irrelevant of values of the elements. The last level must also be filled left to right first
What is the main property of a heap’s organization
The value of each node must be less than or equal to all of the values in its sub trees.
Are duplicate values allowed in heaps
yes
What must be done when inserting a new value into a heap
You must percolate up and make sure that the newly inserted value is less than or equal to each value below it. The new node will start at the right most open spot on the last level
What is one reason one would chose a heap over a multiset
The heap is more memory efficient and equally as time efficient
What is the run time complexity of making a heap from a vector
O(n)