Binary Heaps & Priority Queues Flashcards

1
Q

What are the API methods for a binary heap

A

Push(v)
Min()
Pop()
Size()
Empty()
Clear()

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

Define what a heap is

A

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

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

What is the main property of a heap’s organization

A

The value of each node must be less than or equal to all of the values in its sub trees.

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

Are duplicate values allowed in heaps

A

yes

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

What must be done when inserting a new value into a heap

A

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

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

What is one reason one would chose a heap over a multiset

A

The heap is more memory efficient and equally as time efficient

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

What is the run time complexity of making a heap from a vector

A

O(n)

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