Heaps Flashcards

1
Q

What is a ‘Priority Queue’ and what operations does it support?

A

An abstract data type that is similar to a regular queue, with the difference being that every item has a priority associated with it.

Additional Operations: Insert(x), deleteMin(x)

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

What are the runtimes for Linked lists, Balanced BSTs, and Heaps that implement priority queues?

A

Linked list
1. Insert(x): Theta(1)
2. deleteMin(): Theta(N)

Balanced BST
1. Insert(x): Theta(lnN)
2. deleteMin(): Theta(lnN)

Heaps
1. Insert(x): Theta(1)
2. deleteMin(): Theta(N)
3. Sorting: nlnN

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

What is a ‘heap’ data structure, and what are its traversal equations?

A

A heap is essentially a ‘complete’ tree stored in ‘level order’ inside an array.

Traversal Equations:
leftChild(i) = 2i
rightChild(i) = 2i+1
parent(i) = [i/2]

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

What are the two types of heaps.

A

Min-Heap ( >= x): The values of all the nodes in the subtree rooted in n are >= x.

Max-Heap ( <= x): The values of all the nodes in the subtree rooted in n are < = x.

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

What type of tree is stored in a heap?

A

A complete tree

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

What order do heaps store trees?

A

Level-order

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

What are the heap operation runtimes?

A

height: ln N
insert(x): O(lg N)
deleteMin(): O(lg N)
getMin(): Theta (1)

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

How are heaps built?

A

From the bottom up.

  1. Begin with an unordered array.
  2. Make sure that all subtrees in the last two layers are heaps.
  3. Move up layer by layer.

percolate Down(i) assumes that both subtrees under i are already heaps?

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