Heap Sort Flashcards

1
Q

What is a heap data structure?

A

An ordered binary tree

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

What is a max heap?

A

A heap where the value of parent nodes is greater than the value of child nodes.

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

What is an in-place algorithm?

A

An algorithm that operates directly on the input data structure and does not require any extra space

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

What are two in place sorting algorithms?

A

Heapsort, quicksort

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

What are applications of the heap data structure?

A

Heap sort, priority queue.

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

What is a nearly complete binary tree?

A

A tree that is completely filled on all levels except possibly the lowest which is filled from left up to a point.

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

What is a complete k-ary tree

A

A k-ary tree in which all leaves have the same depth and all internal nodes have degree k (CLRS)

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

How many internal nodes does a complete binary tree have?

A

2^h - 1 (where h is height)

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

With starting index at 1, what index is the root of the tree?

A

1

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

With starting index at 1, what index is the parent of the A[i]?

A

A[floor(i/2)]

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

With starting index at 1, what index is the left child of A[i]?

A

A[2i]

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

With starting index at 1, what index is the right child of A[i]?

A

A[2i + 1]

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

What is the height of node in a heap?

A

edges on the longest simple downward path from the node to a leaf

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

What is a min-heap?

A

Opposite of max heap; root has the smallest element

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

What is a priority queue?

A

A data structure for maintaining a set S of elements, each with an associated value called a key. It is a sorted Queue data structure.

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

What is the difference between a stack and a queue?

A

Stack: LIFO
Queue: FIFO

17
Q

What is the maximum element of a max-heap?

A

The root

18
Q

After heapify is applied to a priority queue, what is the time complexity of accessing the min/max value?

A

O(1)

19
Q

What are the three properties of a priority queue?

A
  1. Every item is associated with a priority
  2. High priority remove first
  3. If 2 elements have same priority, they are removed according to their order in the queue.