Heaps Flashcards

1
Q

A ______________ is a special queue where the key with the highest priority is found at one end.

A

Priority Queue

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

These are used to schedule jobs on a computer shared among multiple uses.

A

Priority Queue

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

The ______ indicate the priority.

A

Key

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

The _________ data structure is an array that we can view as a nearly complete binary tree.

A

(Binary) Heap

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

True or False:

In a Heap, the tree is always full on all levels.

A

FALSE. It can possibly be not full at the bottom most level.

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

TRUE OR FALSE:

A heap is filled from left to right

A

True

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

In a heap represented by an array, the root of the tree is stored at which index.

A

1

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

For any node at index n, its parent is at index?

A

n//2

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

For any node at index n, its left child is at index?

A

2n

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

For any node at index n, its right child is at index?

A

2n + 1

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

For every node other than the root, the value of a node is at most the value of its parent.

A

max-heap

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

The __________ in a max heap is at the root.

A

largest value

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

For every node other than the root, the value of a node is at least the value of its parent.

A

min-heap

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

The __________ in a min heap is at the root.

A

smallest value

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

Synonyms are sift-up, float up, min-heapify

A

percolate up

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

To delete in a heap:

A

1) Swap root with last key
2) Update heap size
3) Fix up from the root (percolate down)

17
Q

How to build a heap given an array,

A

Starting from index i/2 (i is size of array) to 1, percolate down.

18
Q

Run times for using a heap for a priority queue

A

insert O(log n)
delete min/max - O(log n)
build-heap - O(n)

19
Q

A sorting algorithm that call build-max-heap, then performs n-1 delete-max operations

A

Heap Sort

20
Q

What is the running time of heap sort:

Hint: build-heap O(n)
n-1 delete O(n log n)

A

O(n log n)