#### Computing the Minimum Number of Flight Segments

If we want to compute the minimum number of flight segments between a starting city and target city, we can construct an undirected graph. In the graph the nodes represent cities and the edges represent the flight segments. We can count the number of segments to determine the shortest distance.

The following can be applied to any situation in finding the shortest path. It is an implementation of the breadth first search algorithm.

See code below.