Finding a shortest path that passes through some arbitrary sequence of nodes?
In this earlier question the OP asked how to find a shortest path in a graph that goes from u to v and also passes through some node w. The accepted answer, which is quite good, was to run Dijkstra's algorithm twice - once to get from u to w and once to get from w to v. This has time complexity equal to two calls to Dijkstra's algorithm, which is O(m + n log n). Now consider a related question - you are given a sequence of nodes u 1 , u 2 , ..., u k and want to find the shortest path from u 1 to u k such that the path passes through u 1 , u 2 , ..., u k in order. Clearly this could be done by