Priority Queue and Heap Flashcards

1
Q

What is the runtime of insert?

A

log(n)

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

What is the runtime of deleteMin (or deleteMax depending on priority)?

A

log(n)

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

What can priority queue not do?

A

No searching, no sorting.

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

Why do the operations get log time?

A

Because we use a heap and because of the following setup of the array:
left child: 2i (i being the element we’re currently at)
right child: 2i+1
your parent: i/2 (integer math so chops off the decimal)

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

What does heap look like?

A

It looks like a binary tree, but it is an array.

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

What is the heap implemented by?

A

Heap is implemented by using an array, NOT A LINKED LIST.

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

What is the priority queue implemented by?

A

Implemented by using heap (the structure).

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

What is min heap?

A

Everything under is bigger

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

What is max heap?

A

Everything under is smaller

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

Where do we start when inserting?

A

We start at the bottom when inserting. A hole is added to the end and moved up.

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

Where do we start when deleting?

A

We start at the top when deleting. A hole is added to the top and moved down. We always take off the top.

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