## #4731 closed Bugs (fixed)

# Documentation for dijkstra shortest path is wrong

Reported by: | Owned by: | Andrew Sutton | |
---|---|---|---|

Milestone: | To Be Determined | Component: | graph |

Version: | Boost 1.44.0 | Severity: | Problem |

Keywords: | bgl graph dijaksta shortest path minimum spanning tree | Cc: |

### Description

In the documentation for dijkstra_shortest_paths, you can read:

"The predecessor map records the edges in the minimum spanning tree. Upon completion of the algorithm, the edges (p[u],u) for all u in V are in the minimum spanning tree."

I would say, that this is wrong: Dijkstra won't give you a minimum spanning tree in all cases.

One counterexample would be a undirected graph with the vertices (0,1,2) and the following edges (format is start,point, endpoint, weight):

(0, 1, 2) (0, 2, 3) (1, 2, 4)

This graph has only one minimum spanning tree with the predecessors map (2,0,2) - which is what you get with prim. If you execute dijkstra shortest path on this graph, you will get (2,2,2) - and this is not a minimum spanning tree (since the weight of this tree is 7, while the weight of the minimum spanning tree is 5).

Find attached an example which calculates both algorithms on these two graphs. I really think this should be fixed in the documentation.

### Attachments (1)

### Change History (7)

### Changed 7 years ago by

### comment:1 Changed 7 years ago by

I agree. The search tree computed by SP algorithm is not guaranteed to be a MST. Updated the documentation to describe the results in terms of a "search tree" with a statement claiming that it is not guaranteed to be an MST.

Changes in r65939.

### comment:2 Changed 7 years ago by

Resolution: | → fixed |
---|---|

Status: | new → closed |

### comment:3 Changed 7 years ago by

Resolution: | fixed |
---|---|

Status: | closed → reopened |

The term "search tree" used in the current fix is misleading/imprecise depending how you define "search tree". Either use a term like "fully relaxed search tree" or another term like "spanning tree describing all shortest paths from the specified start vertex".

Observe that the spanning tree encoded in the predecessor map describes the shortest path to every vertex in the graph from the defined start vertex. This is usually NOT equal to the "search tree" describing the order in which dijkstra explored the edges (without applying relaxation to this tree).

To observe the difference between "fully relaxed search tree" and "search tree" the following example:

Given a graph on vertices {0, 1, 2} and edges (0, 1, 2), (1, 2, 4), (0, 2, 3) where the format is (start point, end point, weight).

For running dijkstra on it with start vertex 1:

- The "Search tree" in my eyes would be (1, 1, 0) (to be read as the predecessor map)
- The predecessor map (result of dijkstra) is: (1, 1, 1)

### comment:4 Changed 7 years ago by

It may be the case that such descriptions are more precise, but I feel that they are unnecessary. I may consider redefining it as "the tree computed by the algorithm" rather than "traversal", but I'm not going to try to be more specific.

The reason is that those specific properties of the tree are imposed by the completion of the algorithm--not guaranteed by tree itself. If the algorithm fails to complete or is terminated early, by exception for example, neither description would be correct. However, a search tree on input will still be a search tree on output, regardless of the termination state of the algorithm.

### comment:5 Changed 7 years ago by

Resolution: | → fixed |
---|---|

Status: | reopened → closed |

**Note:**See TracTickets for help on using tickets.

Implementation of the example described in the bug report