Binary Heap Flashcards

1
Q

What is a binary heap

A

an array representation of a heap ordered complete binary tree

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

what is a property of heap order

A

every node key must be greater than than it’s child node

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

what number do the indices start at in binary heap representation

A

at 1

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

where is the largest key in a binary heap

A

root

pos 1

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

how to insert into a binary heap

A

add node at end

swim it up

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

how to remove maximum from a binary heap

A
exchange root(max) with node at the end
sink new root down to its correct positio
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

cost of insertion into a heap

A

at most 1+logN compares

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

cost of deleting max in binary heap

A

logN

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

cost of finding max in binary heap

A

1

is the first element

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

best case of insertion and deletion is when…

A

no sinking is needed

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

why is binary heap more efficient than using arrays

A

splits searching time

array = N compares at most
binary heap = log N compares at most = holy grail

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

how is heap sort implemented

A

build max heap using bottom up method

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

worst case run time of heap sort

A

N log N

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

what does it mean for an algorithm to be stable

A

preserves the order of duplicate keys

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

what does it mean for an algorithm to be in place

A

does not need new memory allocated

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

is mergesort an in place sorting algorithm

A

no, linear extra space is neede

17
Q

is quicksort an in place sorting algorithm

A

yes

18
Q

is quicksort a stable sorting algorithm

A

no

19
Q

is merge sort a stable algorithm

A

yes

20
Q

heap sort algorithm run time guarantee (average)

A

N log N

21
Q

heap sort algorithm best case run time

A

N