- Priority queue abstract data type, implementations: unsorted list, sorted list, bucket queue
- Heap data structure, binary heap representations: binary tree, array
- Heap sort, compare to selection sort, insertion sort and tree sort
- Review Make School's priority queue and heap slides
- Watch Make School's heap video lecture
- Watch HackerRank's heap video
- Watch this cute robot heap sort animation video
- Play with VisuAlgo's interactive heap visualization
- Read Vaidehi Joshi's article on heaps and heap sort with beautiful drawings
- Read CMU's lecture notes on binary heaps and priority queues
- Read about how sorting algorithms can be generalized with different priority queue implementations
- Implement
BinaryMinHeapclass using dynamic array with the following instance methods using binary heap starter code:is_empty- check if the heap is emptysize- return the number of items in the heapinsert(item)- insertiteminto this heapget_min- return the minimum item at the root of the heapdelete_min- remove and return the minimum item at the root of the heapreplace_min(item)- remove and return the minimum item, and insertiteminto this heap_bubble_up(index)- ensure the heap ordering property is true aboveindex, swapping out of order items_bubble_down(index)- ensure the heap ordering property is true belowindex, swapping out of order items
- Run
python binaryheap.pyto testBinaryMinHeapclass instance methods on a small example - Run
pytest binaryheap_test.pyto run the binary heap unit tests and fix any failures - Implement
heap_sortalgorithm with binary heap (Hint: this is super easy) - Implement
PriorityQueueclass using binary heap with the following instance methods using priority queue starter code:is_empty- check if the priority queue is emptylength- return the number of items in the priority queueenqueue(item, priority)- insertiteminto the priority queue in order according topriorityfront- return the item at the front of the priority queue without removing it, or Nonedequeue- remove and return the item at the front of the priority queue, or raise ValueErrorpush_pop(item, priority)- remove and return the item at the front of this priority queue, and insertitemin order according topriority
- Annotate methods with complexity analysis of running time and space (memory)
- Implement stack with priority queue (Hint: this is simple if you use priority values cleverly)
- Implement double-ended priority queue with binary search tree (allow access to min and max item)
- Create a generic
BinaryHeapclass with an initialization option to choose min or max heap order