You are given the information about the flight network between various cities as a graph G = (V, E): the vertex set V is the set of cities and there is an edge between two cities u, v if there is a direct flight between the two cities. Your goal now is to determine the worst-case number of stops (or connecting flights) a person needs to make to travel between two different cities. For example, if V = {LA, Chicago, NY C, SF, London} and E = {{LA, Chicago}, {Chicago, NY C}, {LA, NY C}, {SF, LA},{SF, Chicago}, {NY C, London}}. Then, the answer is 2 as you need that many stops to go from SF to London. Give an algorithm which runs in time O(|V | ·(|V | + |E|)) to solve this problem. You should state the algorithm clearly, prove its correctness and prove its time complexity.
Get Free Quote!
272 Experts Online