Heaps Flashcards

1
Q

What is the difference between a min-heap and a max-heap?

A

Min-Heap: smallest element at root; Max-Heap: largest element at root.

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

What is the time complexity of inserting into a heap?

A

O(log n).

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

What is the time complexity of extracting the min/max from a heap?

A

O(log n).

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

How can you find the k-largest elements in an array?

A

Use Min-Heap of size K.

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

How does a min-heap differ from a max-heap?

A

Min-Heap stores smallest element at root, Max-Heap stores largest.

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

What is the time complexity of sorting a heap?

A

O(n log n).

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