Just like FIFOs and LIFOs, min-heaps store elements
Two methods:
push
pop
“smallest” needs to be clarified
# Create a min-heap heap = new_heap()
[]
# Add elements to the heap push(heap, ("A", 50)) push(heap, ("B", 22)) push(heap, ("C", 10))
[('A', 50), ('B', 22), ('C', 10)]
# Extract smallest element from the heap pop(heap)
('A', 50)
Dijkstra’s algorithm extends BFS to weighted graph
Think of water flowing through the graph at a constant speed
We didn’t talk about routing tables but you will need one to retrieve the path
Min-heaps are data structure that pop the minimum element
Many implementations are possible, beware of details!
Dijkstra’s algorithm is a traversal that exploits the properties of a min-heap
Remember the relation between BFS/queue and DFS/stack