#graphs

1 article tagged “graphs”.

A weighted graph of six nodes with the shortest-path tree from A highlighted and each node labelled with its distance
AlgorithmsAdvanced

Dijkstra's Algorithm: Shortest Paths with a Priority Queue

Implement Dijkstra's shortest-path algorithm in Python with heapq, trace it step by step, understand why it's correct, and learn exactly when it breaks: negative edges, ties in the heap and dense graphs.

7 min read