Loading topic
dijkstra function. It also assumes you are comfortable with Python dictionaries and lists. So far the algorithm tells you how far each vertex is from the source. Most real uses also need the route itself: the turns a navigation a2 min readdijkstra function from earlier chapters and the greedy invariant: once a vertex is popped from the heap, its distance is final. That invariant depends on one condition, which is that every edge weight is non-negative. When an edge weight is nega3 min readheapq and lazy deletion. Throughout, V is the number of vertices and E is the number of edges.2 min readdist and visited, and the idea of edge relaxation. It also helps to have seen the negative-weight counterexample, because the proof below shows exactly where that example fails.3 min readdijkstra function and the idea that a vertex's distance is final once it is popped.2 min readheapq, Big-O notation, and the idea that Dijkstra's algorithm pushes a vertex again whenever its tentative distance improves.3 min read