Chapter 6 (Priority Queues (Heaps)) Flashcards

1
Q

What is the big-O time to search for a min in a linked list?

A

O(n) since you might have to search the whole list

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

What is the insert and remove min for a binary heap?

A

O(log n)

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

When is a binary tree complete?

A

Every node has two children except the last level which is filled from left to right

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

How does a sorted linked list affect the search for a min and inserting?

A

Search for a min becomes O(1) since it’s sorted, but insert becomes O(n) because it may have to traverse to the end of the list for the insert.

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

T/F The npl of any node is two more than the minimum npl’s of its children

A

F, one more

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

What is the NPL of a null?

A

-1

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

Where is the maximum value in the heap-order property?

A

In a leaf node

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

What’s the difference between a leftist heap and skew heap?

A

The skew heap does not compare left and right subtree’s, it always swaps after a merge no matter what.

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

T/F The structure of a heap is a binary tree that is completely filled except possibly the bottom level, which is filled left to right

A

T

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

What are two operations that a priority queue, at the minimum, supports?

A

Insert (enqueue) and deleteMin (similar to dequeue)

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

When is a binary tree perfect?

A

Has exactly 2^(h+1)-1 nodes where h is the height

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

What does a delete need?

A

decreaseKey to minimum then deleteMin

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

Since there are at most log N different trees, each with its minimum at its root, the heap’s minimum can be found in ____ time

A

O(log N)

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

Leftist heaps use a ____ of a node, which is the length of the shortest path from the node to a node without two children

A

“null path length”

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

What is the NPL of a node with 0 or 1 child?

A

0

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

What does decreaseKey require?

A

Percolate up

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

With the heap-order property, what is the running time for the findMin operation?

A

O(1)

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

What does increasKey require?

A

Percolate down

19
Q

What two things have to be done for deleteMin?

A

Remove the root value Re-arrange the heap to preserve the heap-order property

20
Q

What is a d-heap?

A

Has d children per parent

21
Q

What is the running time of buildHeap?

A

O(N)

22
Q

T/F Each item in a queue is treated equally

A

T

23
Q

What is the advantage of a d-heap having d children?

A

Results in a shallower tree, which improves performance of inserts

24
Q

What two things must be done for an insert with a binary heap?

A

Insert into the next available node Re-arrange the heap to preserve the heap-order property

25
Q

What is the leftist heap property?

A

For every node, the npl of its left child is at least as large as the npl of its right child

26
Q

A right child’s number is ____ its parent’s number

A

2X+1

27
Q

When is a binary tree full?

A

Every node is either a leaf or has two children

28
Q

What are leftist heaps designed to support?

A

Efficient merging of two heaps

29
Q

What does buildHeap do?

A

Takes N items and builds a heap

30
Q

What type of data structure is a queue?

A

FIFO

31
Q

What is the heap-order property?

A

Any node should be smaller than all of its descendants

32
Q

What is the running time of insert and remove min for a balanced search tree?

A

O(log n)

33
Q

What is “percolate up”?

A

Create a node, check ordering, if not OK then swap with parent, repeat until the node is in its proper position

34
Q

A complete binary tree of height h always has between ____ and ____ nodes, which leads to performance of ____

A

2^h, 2^(h+1)-1, O(log N)

35
Q

T/F A priority queue is a data structure that orders its items by priority

A

T

36
Q

What other heap operations might we have?

A

decreaseKey increaseKey delete buildHeap

37
Q

Binomial queues are essentially a forest of heap-ordered trees where each tree of height k has exactly ____ nodes, and there can be at most one tree of each height

A

2^k

38
Q

What is “percolate down”?

A

Repeat sliding the hole node down until the last node value can occupy this node while preserving the heap-order property

39
Q

Binomial queues have ____ time on insert, deleteMin, and merge, but have ____ average time on an insert

A

O(log N), O(1)

40
Q

What is the disadvantage of a d-heap having d children?

A

deleteMin may suffer because finding minimum child of a node is now harder

41
Q

What are the advantages of storing a heap in an array?

A

No links (pointers), operations to traverse are fast

42
Q

A left child’s number is ____ its parent’s number

A

2X

43
Q

Any parent number is ____

A

X/2