Priority Queue and Heap Flashcards
What is the runtime of insert?
log(n)
What is the runtime of deleteMin (or deleteMax depending on priority)?
log(n)
What can priority queue not do?
No searching, no sorting.
Why do the operations get log time?
Because we use a heap and because of the following setup of the array:
left child: 2i (i being the element we’re currently at)
right child: 2i+1
your parent: i/2 (integer math so chops off the decimal)
What does heap look like?
It looks like a binary tree, but it is an array.
What is the heap implemented by?
Heap is implemented by using an array, NOT A LINKED LIST.
What is the priority queue implemented by?
Implemented by using heap (the structure).
What is min heap?
Everything under is bigger
What is max heap?
Everything under is smaller
Where do we start when inserting?
We start at the bottom when inserting. A hole is added to the end and moved up.
Where do we start when deleting?
We start at the top when deleting. A hole is added to the top and moved down. We always take off the top.