Functions
shortest_path
Computes weight and predecessor tables using Dijkstra’s algorithm.The graph to search (must have
adjacent_items() method for weighted edges)The starting vertex label
The ending vertex label
If True, displays the weight table as it is being built during the algorithm execution
Dictionary mapping vertices to their shortest distance from the start vertex
Dictionary mapping each vertex to its predecessor in the shortest path from start
KeyError: If start or end vertex is not in the graph
find_path
Finds the shortest path between two vertices using Dijkstra’s algorithm.The graph to search (must have
adjacent_items() method for weighted edges)The starting vertex label
The ending vertex label
If True, displays the weight table, predecessor table, and shortest path weight
List of vertices forming the shortest path from start to end
KeyError: If start or end vertex is not in the graph, or if there is no path from start to end
Algorithm Complexity
Algorithm Complexity
Time Complexity: O((V + E) log V) where V is the number of vertices and E is the number of edgesSpace Complexity: O(V) for storing the weight table, predecessor table, and priority queueThe algorithm uses a min-heap priority queue to efficiently select the next vertex with minimum distance.