Introduction
Finding the fewest connections between two points is a problem that appears in maps, social networks, computer systems, and many other settings. The mathematics behind it is called graph theory. By representing objects as points and their relationships as links, we can turn a complicated network into a structure that an algorithm can search systematically.
- The basic idea: represent a network as a graph
- A small example
- How breadth-first search finds the fewest connections
- Finding the route, not just its length
- Disconnected networks and unreachable destinations
- When connections have different costs
- How much work does the search require?
- Where the mathematics is useful
- What “fewest connections” does not tell you
- Conclusion
The basic idea: represent a network as a graph
A graph is a mathematical model made from vertices and edges. A vertex represents an object, such as a place, person, or web page. An edge represents a connection between two objects. In a route map, for instance, intersections can be vertices and roads can be edges.
When the links have no stated direction, the graph is undirected: if A is connected to B, B is also connected to A. A one-way street or a web link can be represented by a directed edge, which allows travel in only one direction. The direction matters because a route that works from A to B may not work from B to A.
In this model, a route is a sequence of edges joining one starting vertex to a destination. The number of edges in that route is its length when every connection counts equally. The central question is: among all possible routes between the two vertices, which has the smallest number of edges?
This is called the shortest-path problem in an unweighted graph. “Shortest” here means fewest connections, not necessarily least distance, least time, or lowest cost. Those other meanings require additional information about the edges.
A small example
Imagine a network with these connections: A–B, A–C, B–D, C–D, and D–E. To get from A to E, one possible route is A–B–D–E. Another is A–C–D–E. Each uses three edges, so both are shortest routes in terms of number of connections.
There may be several shortest routes, even though they all have the same length. The mathematics is not necessarily trying to pick one uniquely preferred route. It finds the minimum number of edges and can, if needed, identify every route that achieves that minimum.
If a new direct connection A–E is added, the fewest-connection route becomes one edge long. This shows why the answer depends on the network’s structure: changing a single connection can alter the shortest path.
How breadth-first search finds the fewest connections
For an unweighted graph, a standard method is breadth-first search, often shortened to BFS. The name describes its strategy: starting at the source, it explores every vertex one connection away, then every vertex two connections away, then every vertex three connections away, and so on.
This layer-by-layer approach is exactly suited to counting connections. If the destination first appears in the layer three edges from the start, no route of one or two edges can reach it. BFS has already checked all possibilities at those smaller distances.
The search process
1. Begin at the starting vertex and mark it as visited. Give it a distance of zero, because reaching it requires no edges.
2. Place it in a queue, a collection that processes items in the order they were added. A queue helps ensure that earlier, closer vertices are explored before later ones.
3. Remove the next vertex from the queue and examine its neighbors. For every neighbor not already visited, mark it as visited, record its distance as one more than the current vertex’s distance, and add it to the queue.
4. Continue until the destination is reached or the queue is empty. If the queue empties before the destination is found, there is no route between the two vertices in the graph.
In the example above, BFS starts at A. It discovers B and C at distance one. From those, it discovers D at distance two. From D, it discovers E at distance three. The search therefore establishes that three is the fewest possible number of connections.
Why the result is guaranteed to be shortest
The guarantee comes from the order of exploration. BFS finishes examining all vertices at distance zero before moving to distance one, and all vertices at distance one before moving to distance two. A vertex is first reached by a route with the smallest number of edges because any shorter route would have been explored in an earlier layer.
This reasoning depends on treating every edge as one step. If one connection represents a short walk and another represents a long journey, counting each as one does not find the route with the least physical distance. It finds only the route with the fewest links.
Finding the route, not just its length
Sometimes the minimum number is enough. In other cases, a person needs the actual sequence of connections. BFS can provide both by recording a predecessor for each newly discovered vertex: the vertex from which it was first reached.
For example, if the search records that D was first reached from B and E was first reached from D, tracing backward from E gives E, D, B, A. Reversing that sequence produces the route A–B–D–E.
If more than one shortest route exists, the predecessor record may preserve only one, depending on the order in which neighbors are examined. To find all shortest routes, a search can also record every predecessor that reaches a vertex at the same minimum distance. This creates a compact description of the alternative paths rather than requiring the search to treat a longer route as equally good.
Disconnected networks and unreachable destinations
A graph can contain separate regions with no connections between them. Such regions are called connected components in an undirected graph. If the start and destination are in different components, there is no path between them, so no finite number of connections will reach the destination.
In a directed graph, reachability can be one-way. A may be able to reach B even when B cannot reach A. Therefore, a search must follow the direction of each edge rather than assuming that every link can be traversed both ways.
These distinctions matter in practical systems. A road map may have temporary or permanent barriers, while a computer network may contain links that carry information only in a specified direction. The mathematical model must reflect the connections that are actually allowed.
When connections have different costs
Many networks attach a value to each edge. A road might have a travel distance, a flight connection might have a duration, or a delivery link might have a cost. In that case, the goal may be to minimize the sum of edge values rather than the number of edges.
Suppose one route uses two connections with a total travel time of five hours, while another uses three connections totaling three hours. BFS would prefer the two-connection route because it counts edges. If the goal is minimum travel time, that answer may be wrong.
For nonnegative edge costs, a common method for finding a minimum-cost path is Dijkstra’s algorithm. Unlike BFS, it selects the next vertex according to the best total cost found so far, not simply according to the number of edges from the start. If all edges have the same cost, minimizing total cost and minimizing the number of edges produce the same result, and BFS is sufficient.
Thus, choosing the right method begins with defining “fewest” precisely. Is the goal to minimize the number of links, the distance traveled, the time taken, or some other total? The graph’s edge values and the intended meaning of the question determine the suitable algorithm.
How much work does the search require?
With an efficient representation of the graph, BFS takes time proportional to the number of vertices and edges: commonly written as O(V + E), where V is the number of vertices and E is the number of edges. In plain language, the search examines each vertex and connection only a limited number of times.
It also stores information such as which vertices have been visited, their distances, and optionally their predecessors. The amount of storage is proportional to the size of the graph. This is one reason BFS works well for large networks when their connections can be stored and accessed efficiently.
The formula describes how the workload grows as a network grows; it is not a promise of a particular running time on every device. The practical speed also depends on how the graph is stored, the size of the network, and the computing environment.
Where the mathematics is useful
Transit and route planning: A simplified transit model can treat stations as vertices and direct services as edges. BFS can find the fewest transfers or segments when each edge is counted equally. A real journey planner may instead account for travel time, waiting, service schedules, or accessibility.
Social networks: People can be represented as vertices, with a connection such as a mutual contact represented as an edge. A shortest path then describes the fewest links between two people in the model. It does not measure the strength, quality, or real-world importance of those relationships.
Web and information networks: Web pages can be modeled as vertices and links between pages as directed edges. Searching such a graph can answer questions about reachability or link distance, although the web is large and constantly changing, so practical systems often use specialized techniques.
Computer networks and puzzles: Devices and communication links can form a graph in which a search finds a route through available connections. In a puzzle, each possible state can be a vertex and each legal move an edge; BFS can find a solution that uses the fewest moves when all moves count equally.
What “fewest connections” does not tell you
A minimum-edge path is a structural answer, not a complete judgment about what route is best. It does not automatically account for reliability, safety, price, comfort, congestion, or the time required to use each connection. Those considerations need to be represented in the model if they are part of the question.
The result also depends on what counts as a vertex and an edge. If a transit system models each station as a vertex, one train ride between adjacent stations may count as one edge. If it models entire lines differently, the same journey can have a different edge count. A useful model is one that represents the real question clearly.
Finally, the shortest path is defined relative to the connections included in the graph. Missing information, outdated links, or unrealistic assumptions can lead to an answer that is mathematically correct for the model but unhelpful in practice. The algorithm can search the network accurately; it cannot repair a poor representation of that network.
Conclusion
The fewest-connections problem is a shortest-path problem in an unweighted graph. Breadth-first search solves it by exploring outward in layers, ensuring that the first route found to a destination uses the minimum number of edges. When connections have different costs, a weighted-path method may be needed instead. In every case, the answer depends on how the network and its connections are defined.

