The weights in a weighted graph can be used to model various concepts. How we combine the weights—or even what type of values are used for the weights—depends on what we have in mind. In general, the important questions to ask about weights are:
- How do we combine the weights of two paths in series (i.e. when the two paths are sequenced end-to-end into a longer path)?
- How do we combine the weights of two paths in parallel (i.e. when we have two different paths between the same two start and end vertices)?
- How do we decide which of two weights is "better"?
For example, when weights represent a cost:
- We add the weights of two paths in series.
- We take the minimum of the weights of parallel paths.
- Smaller weights are better.
However, if weights represent a capacity, we might answer these questions differently:
- When paths are in series, we take the minimum weight: the smallest-capacity path is the bottleneck and determines the capacity of the whole composed path.
- When paths are in parallel, we either take the maximum (if we want to pick the higher-capacity path) or we add (if we are allowed to use both paths at once and we know the paths don't overlap at all).
- Bigger weights are better.
As another example, if weights represent some kind of probability, then we might multiply weights in series and take the maximum in parallel. Weights don't even have to be numbers! If weights are, say, strings, we might concatenate them in series and take the shorter of two strings in parallel (what would a "best path" mean in this context?).
We introcued algorithms like Dijkstra and Floyd-Warshall as algorithms to find shortest paths, but really they are algorithms for finding "best" paths: we can plug in any operations for combining weights we like (as long as they satisfy some nice algebraic properties like distributivity). For example, if we substitute the operations (\min , \max ) in place of (+, \min ), then Dijkstra and Floyd-Warshall find maximum-bottleneck paths: i.e. paths such that the minimum capacity along the path is as large as possible.