Final answer:
An algorithm to compute the number of shortest paths between two nodes in an undirected graph can be created by modifying the Breadth-First Search algorithm to track the distance and the number of shortest paths to each node. The run time is O(m+n).
Step-by-step explanation:
The designing an algorithm to compute the number of shortest paths between two nodes in an undirected graph, specifically, from node v to node w. To answer this, we can modify the Breadth-First Search (BFS) algorithm. The modification involves keeping track of two additional data for each node: the distance from the start node v, and the number of shortest paths that reach the node.
Initialize the number of paths to v as 1 and the rest as 0. Perform a BFS starting from node v. When a node is explored for the first time, update its distance to be one more than the distance of its predecessor. If an unvisited neighbor is discovered and it contributes to a shortest path, increase its number of paths by the number of paths to the current node.
If a neighbor is discovered that has been visited and the current path is also a shortest path (equal distance as recorded), increment the neighbor's path count by the current node's path count. Continue the search until node w is reached, and the result will be the number of shortest paths to node w. The run time remains O(m+n) since we are simply augmenting the standard BFS with additional bookkeeping that does not increase the asymptotic complexity.