Shortest Path Algorithm - Graph Algorithm

Find the path between vertices A and B (if exists) that has the minimum weight (sum of the weights of the traversed edges).

 

An Example - Travel - Shortest Path Algorithm

How can I find the shortest path from Austin to Washington?

There are multiple paths:

1560 miles: Austin->Houston->Atlanta->Washington

2980 miles: Austin->Dallas -> Denver -> Atlanta -> Washington

 

Another Example: Routing - given we represent our computer network with a graph (routing computers are vertices) how do send a message from computer A to computer B most efficiently?

Edges - Weights related to traffic between 2 nodes at given time.

Vertices - routers.

Shortest Path - represents path to send message the quickest.

Algorithms:

To be able to find the shortest path between 2 vertices, you must look at all possible paths between them and calculate the weight. This can take a lot of time and there are a number of algorithms that have been proposed to handle this. There are also algorithms that are proposed that do not find the absolute shortest path but, instead find a "short" path, these are called approximate solutions. Many corporations as well as scholars are searching for good algorithms to solve this problem.

 

  • Simple (not too efficient) Solution - calculate the shortest path from the starting vertex to evy other vertex in the graph. Then you can retrieve the shortest path for the ending vertex of interest.
  • Dijkstra's algorithm (see also here) — solves single source problem if all edge weights are greater than or equal to zero. Without worsening the run time, this algorithm can in fact compute the shortest paths from a given start point s to all other nodes. Animation of algorithm
  • Bellman-Ford algorithm — solves single source problem if edge weights may be negative.
  • A* search algorithm — solves for single source shortest paths.
  • Floyd-Warshall algorithm — solves all pairs shortest paths.
  • Johnson's algorithm — solves all pairs shortest paths, may be faster than Floyd-Warshall on sparse graphs.
  • Perturbation theory — finds (at worst) the locally shortest path

 

Example 2- Travel - Shortest Path Algorithm

How can I find the shortest route from one intersection to another.


Graph vertices - intersections of roads

Graph edges - roads connecting intersections (vertices), or ending at culdesacs (dead ends) vertices.

Edge weights - place a number associated with each edge (road), that give the distance of the road between its 2 vertices (intersections).

Directed or Not? - if you have one way roads you may want to represent your road map with a Directed Graph.

cost of a path - sum of weights of edges in path

You could modify the weights to include interesting things like current traffic, possible road work.

 

 

HARDER Problem : Multi-vertex shortest path problem....The traveling salesman problem:

Need to find the shortest path that goes through every vertex in the graph exactly once, and returns to the start. That problem is NP-Complete, so an efficient solution is not likely to exist.

 

 

© Lynne Grewe