ArticleslgStudy

computer science

Shortest path problem

Shortest path problem is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Shortest path problem rather than just read about it. In short: In graph theory, the shortest path problem is the problem of finding a path between two vertices (or nodes) in a graph such that the sum of the weights of its constituent edges is minimized. The problem of finding the shortest path between two intersections on a road map may be modeled as a special case of the shortest path problem in graphs, where the vertices correspond to intersections and the edges correspond to…

Shortest path problem — main illustration
Shortest path problem — illustration

Key takeaways

  • Shortest path problem belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Shortest path problem to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Shortest path problem from memory before moving on to harder problems.

Reference excerpt

In graph theory, the shortest path problem is the problem of finding a path between two vertices (or nodes) in a graph such that the sum of the weights of its constituent edges is minimized. The problem of finding the shortest path between two intersections on a road map may be modeled as a special case of the shortest path problem in graphs, where the vertices correspond to intersections and the edges correspond to road segments, each weighted by the length or distance of each segment.

Definition The shortest path problem can be defined for graphs whether undirected, directed, or mixed. The definition for undirected graphs states that every edge can be traversed in either direction. Directed graphs require that consecutive vertices be connected by an appropriate directed edge. Two vertices are adjacent when they are both incident to a common edge. A path in an undirected graph is a sequence of vertices P=(v1,v2,…,vn)∈V×V×⋯×V such that vi is adjacent to vi+1 for 1≤i<n. Such a path P is called a path of length n−1 from v1 to vn. (The vi are variables; their numbering relates to their position in the sequence and need not relate to a canonical labeling.) Let E={ei,j} where ei,j is the edge incident to both vi and vj. Given a real-valued weight function f:E→ℝ, and an undirected (simple) graph G, the shortest path from v to v′ is the path P=(v1,v2,…,vn) (where v1=v and vn=v′) that over all possible n minimizes the sum ∑i=1n−1f(ei,i+1). When each edge in the graph has unit weight or f:E→{1}, this is equivalent to finding the path with fewest edges. The problem is also sometimes called the single-pair shortest path problem, to distinguish it from the following variations:

The single-source shortest path problem, in which we have to find shortest paths from a source vertex v to all other vertices in the graph. The single-destination shortest path problem, in which we have to find shortest paths from all vertices in the directed graph to a single destination vertex v. This can be reduced to the single-source shortest path problem by reversing the arcs in the directed graph. The all-pairs shortest path problem, in which we have to find shortest paths between every pair of vertices v, v' in the graph. These generalizations have significantly more efficient algorithms than the simplistic approach of running a single-pair shortest path algorithm on all relevant pairs of vertices.

Algorithms Several well-known algorithms exist for solving this problem and its variants.

Dijkstra's algorithm solves the single-source shortest path problem with only non-negative edge weights. Bellman–Ford algorithm solves the single-source problem if edge weights may be negative. A* search algorithm solves for single-pair shortest path using heuristics to try to speed up the search. Floyd–Warshall algorithm solves all pairs shortest paths. Johnson's algorithm solves all pairs shortest paths, and may be faster than Floyd–Warshall on sparse graphs. Viterbi algorithm solves the shortest stochastic path problem with an additional probabilistic weight on each node. Additional algorithms and associated evaluations may be found in Cherkassky, Goldberg & Radzik (1996).

Single-source shortest paths

Undirected graphs

Unweighted graphs

Directed acyclic graphs An algorithm using topological sorting can solve the single-source shortest path problem in time Θ(E + V) in arbitrarily-weighted directed acyclic graphs.

Directed graphs with nonnegative weights The following table is taken from Schrijver (2004), with some corrections and additions. A green background indicates an asymptotically best bound in the table; L is the maximum length (or weight) among all edges, assuming integer edge weights.

Directed graphs with arbitrary weights without negative cycles

Directed graphs with arbitrary weights with negative cycles Finds a negative cycle or calculates distances to all vertices.

Planar graphs with nonnegative weights

Applications Network flows are a fundamental concept in graph theory and operations research, often used to model problems involving the transportation of goods, liquids, or information through a network. A network flow problem typically involves a directed graph where each edge represents a pipe, wire, or road, and each edge has a capacity, which is the maximum amount that can flow through it. The goal is to find a feasible flow that maximizes the flow from a source node to a sink node. Shortest Path Problems can be used to solve certain network flow problems, particularly when dealing with single-source, single-sink networks. In these scenarios, we can transform the network flow problem into a series of shortest path problems.

Transformation Steps

Create a Residual Graph: For each edge (u, v) in the original graph, create two edges in the residual graph: (u, v) with capacity c(u, v) (v, u) with capacity 0 The residual graph represents the remaining capacity available in the network. Find the Shortest Path: Use a shortest path algorithm (e.g., Dijkstra's algorithm, Bellman-Ford algorithm) to find the shortest path from the source node to the sink node in the residual graph. Augment the Flow: Find the minimum capacity along the shortest path. Increase the flow on the edges of the shortest path by this minimum capacity. Decrease the capacity of the edges in the forward direction and increase the capacity of the edges in the backward direction. Update the Residual Graph: Update the residual graph based on the augmented flow. Repeat: Repeat steps 2-4 until no more paths can be found from the source to the sink.

All-pairs shortest paths The all-pairs shortest path problem finds the shortest paths between every pair of vertices v, v' in the graph. The all-pairs shortest paths problem for unweighted directed graphs was introduced by Shimbel (1953), who observed that it could be solved by a linear number of matrix multiplications that takes a total time of O(V4). For undirected and unweighted graphs, Dory et al. gives an algorithm computing a 2-approximation for all pairs of vertices in O(n2.032) time. In 2026, Gupta and Shandilya gives a randomized algorithm running in O~(n2) time that yields a 2-approximation for all pairs whose distance is at least a fixed constant, with high probability.

Undirected graph

Directed graph

… excerpt ends here. Continue reading the full article.

Illustrations

Shortest path problem: Shortest path (A, C, E, D, F), blue, between vertices A and F in the weighted directed graph
Shortest path (A, C, E, D, F), blue, between vertices A and F in the weighted directed graph

Worked examples

Example 1 — a first encounter with Shortest path problem

Start with the simplest possible case. Write down what Shortest path problem claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Shortest path problem before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Shortest path problem ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Shortest path problem

In research
Shortest path problem appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Shortest path problem in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Shortest path problem is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computational problems in graph theory, Edsger W. Dijkstra, Graph distance, so understanding it makes those chapters shorter.
In everyday life
Look for Shortest path problem outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Shortest path problem” →

How to study Shortest path problem in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Shortest path problem means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Shortest path problem out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Shortest path problem in simple terms?

In graph theory, the shortest path problem is the problem of finding a path between two vertices (or nodes) in a graph such that the sum of the weights of its constituent edges is minimized. The problem of finding the shortest path between two intersections on a road map may be modeled as a special…

Why does Shortest path problem matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Shortest path problem?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Shortest path problem.

Tags

  • Computational problems in graph theory
  • Edsger W. Dijkstra
  • Graph distance
  • Network theory
  • Polynomial-time problems

Keep exploring