Binary Heap Flashcards
What is a binary heap
an array representation of a heap ordered complete binary tree
what is a property of heap order
every node key must be greater than than it’s child node
what number do the indices start at in binary heap representation
at 1
where is the largest key in a binary heap
root
pos 1
how to insert into a binary heap
add node at end
swim it up
how to remove maximum from a binary heap
exchange root(max) with node at the end sink new root down to its correct positio
cost of insertion into a heap
at most 1+logN compares
cost of deleting max in binary heap
logN
cost of finding max in binary heap
1
is the first element
best case of insertion and deletion is when…
no sinking is needed
why is binary heap more efficient than using arrays
splits searching time
array = N compares at most
binary heap = log N compares at most = holy grail
how is heap sort implemented
build max heap using bottom up method
worst case run time of heap sort
N log N
what does it mean for an algorithm to be stable
preserves the order of duplicate keys
what does it mean for an algorithm to be in place
does not need new memory allocated