Heaps Flashcards

Learn

1
Q

How do you create a min-heap from a list?

A

Use a built-in heapify function to arrange the list into heap order.

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

What’s the heap property in a min-heap?

A

Every parent node is less than or equal to its children.

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

What does popping from a min-heap do?

A

Removes and returns the smallest element at the root.

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

What is the time complexity for insert and delete in a heap?

A

O(log n) for both operations.

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

How do you simulate a max-heap using a min-heap?

A

Insert negative values and interpret them accordingly.

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

What does pushing to a heap do?

A

Adds an item and maintains heap order.

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

Why is heapify O(n) instead of O(n log n)?

A

It builds the heap efficiently by working from the bottom up.

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

How does the heap array change with operations?

A

Insertions bubble up; deletions bubble down.

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

What’s a real-world use case for heaps?

A

Priority queues, like task scheduling or event handling.

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