Binary Heap Trees Flashcards

(6 cards)

1
Q

What is a binary heap ?

A

A complete binary tree represented as an array,
Max-heap - Every parent node is greater than or equal to its children,
Min-heap - Every parent node is less than or euqal to its children.

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

What is the Insertion operation for a binary heap ?

A

Insert at the next available spot (bottom layer, left or right),
Swap upwards with the partent until the heap property is restored.
Average: O(1)

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

What is the Deletion opertaion for a binary heap ?

A

Replace root with the last element,
Swap down with the appropriate child until the heap property is restored.
O(log n)

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

What is the Construction operation for a binary heap ?

A

Heapify,
Start from the middle of the array and “bubble down”
More effiecient than inserting one at a time.
O(1)

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

How can we impement Binary heaps ?

A

Using array,
Left child = 2 * i
Right child = 2* i + 1,
Parent = i /2

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

What are the advantages and disadvantages of Binary heaps ?

A

Advantages:
Fast insertion and deletion,
Ideal for quick min/max access,
Memory efficient,
Foundation for HeapSort.

Disadvantages:
Poort at searching,
Not flexible for other types of operations,
Not stable

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