Case Study

Name of the Case Study FP Course Linkage Focus Area Complexity : Graph Traversal. : Problem Solving Techniques : Basic Data structures like array, queues and advanced data structures like graphs : Complex

Problem Statement


Let’s assume that we are interested in airline route between seven cities: Delhi, Mumbai, Jaipur, Pune, Bangalore, Ahmedabad and Goa. Our favorite airline (Spicejet) flies the following routes: Ahmedabad to Goa Ahmedabad to Pune Bangalore to Jaipur Bangalore to Pune Delhi to Jaipur Delhi to Mumbai Goa to Ahmedabad Jaipur to Ahmedabad Jaipur to Delhi Jaipur to Goa Mumbai to Pune Pune to Bangalore Pune to Mumbai Questions :

1. Which structure will be used to represent physical relationship between these airline routes? 2. Which data structure will be used to represent the structure (defined in Q.1) for solving the problem? 3. Design a strategy to find the route (direct or indirect) from one city to another city. 4. Is there any route from Delhi to Goa? (Answer this by analyzing the graph). 5. Apply the strategy discussed in Q.3 to find the route from Delhi to Goa. Solution: 1. Graph.
Jaipur Bangalore Delhi Ahmedabad Pune Goa


We will begin by looking at each city we can reach directly from the originating city. If we find our destination.Case Study 2. Two dimensional array known as Adjacency Matrix . Otherwise. We can store distance or fare between cities instead of 0 or 1 (if provided).e. the search is over. Cities Pune Delhi Goa Jaipur Ahmedabad Mumbai Bangalore Pune 0 0 0 0 1 1 1 Delhi 0 0 0 1 0 0 0 Goa 0 0 0 1 1 0 0 Jaipur 0 1 0 0 0 0 1 Ahmedabad 0 0 1 1 0 0 0 Mumbai 1 1 0 0 0 0 0 Bangalore 1 0 0 0 0 0 0 Adjacency Matrix Representation Adjacency List representation Delhi Jaipur Goa Ahmedabad Mumbai Pune Bangalore Jaipur Ahmedabad Ahmedabad Goa Pune Bangalore Jaipur Mumbai Pune Pune Mumbai Delhi Goa 3. The process continues until we find our destination or determine that we can’t get there from here. This will help us in [INFOSYS LIMITED] CONFIDENTIAL PAGE 2 . Remember that we have to place the originating city of all the adjacent cities in a queue say ORIG. in one stop). we will take each of the places we can reach directly and see if we can reach our destination directly from any one of them (i. in two stop).e. Each city adjacent to the originating city is placed in a queue say ALTER. we repeat the process to see if we can reach our destination from any of the next level of cities (i. we need to remember all the cities (alternate route) we can reach in one stop so that we can fan out from them if we don’t find our destination at the one -stop level. If we can’t. If there is a direct route between two cities then store 1 at their intersection point in 2D array otherwise store 0. If we can’t. We kept track of alternate routes by using a queue. The strategy we will use is first to take our starting city and see if we can reach our destination directly.

Case Study determining the route in the end. D will be placed in ALTER and A. REAR: use to store the rear index of queue from where cities inserted. and we need to guarantee that no city is processed more than once otherwise it becomes an infinite process. C. When processed (to check for adjacent) its STATUS change to 2. 5. STATUS: an array that is use to store the status (0. Here are the steps to find the route between DELHI and GOA. Jaipur ORIG: NULL. CURRENT = Delhi FRONT = 2 ALTER: Delhi. Delhi->Mumbai->Pune->Bangalore->Jaipur->Ahmedabad->Goa. This can be solved by using a STATUS field corresponding to each city. Delhi->Jaipur->Goa. Assumptions:ALTER: a queue use to store the adjacent city ready to be processed. 4. we need to keep track of the adjacent to a city. then B. 1. When selected. 1. ORIG: a queue use to store the originating city of all ALTER cities. A will be placed in ORIG. Delhi. When the destination reached. A. CURRENT: use to store the current processing city. Mumbai. C. Delhi STATUS: Pune 0 [INFOSYS LIMITED] REAR = 3 Delhi 2 Goa 0 Jaipur 1 CONFIDENTIAL Ahmedabad 0 Mumbai 1 Bangalore 0 PAGE 3 . Now if a city have its STATUS=2 then it will not be selected. just back track the ALTER and ORIG to find the route between the source city and destination city. Delhi->Mumbai->Pune->Bangalore->Jaipur->Goa. Three possible routes. If STATUS=0 then the city is not selected. STATUS change to 1 and place it in the ALTER. CURRENT = NULL ALTER: Delhi ORIG: NULL STATUS: Pune 0 Delhi 1 Goa 0 FRONT = 1 REAR = 1 Jaipur 0 Ahmedabad 0 Mumbai 0 Bangalore 0 2. D are adjacent to A. FRONT: use to store the front index of queue from where cities removed. 2) of cities. Naturally. Example if B.

Implementation of Breadth First Search. Delhi. Mumbai. check the last city entered in ALTER and finds its originating city in ORIG. Delhi. To find the route. Delhi. 2. Now find the position of JAIPUR in ALTER and check for its corresponding originating city in ORIG. Mumbai STATUS: Pune 1 Delhi 2 Goa 0 Jaipur 1 Ahmedabad 0 REAR = 4 Mumbai 2 Bangalore 0 4. Jaipur. Hence the route with smallest number of stoppage is:DELHI->JAIPUR->GOA. Repeat this process until you find the originating city NULL. Students will be able to learn how to apply the strategy or algorithm on real world of data to solve the problem. Mumbai. [INFOSYS LIMITED] CONFIDENTIAL PAGE 4 . Jaipur. Pune. Delhi. Jaipur. Originating city of GOA is JAIPUR. 5. CURRENT = Mumbai FRONT = 3 ALTER: Delhi. ALTER: ORIG: Delhi. Pune. Students will be able to understand different data structures like arrays. 4. Learning Outcomes: 1. CURRENT = Jaipur ALTER: ORIG: STATUS: Pune 1 FRONT = 4 REAR = 5 Delhi.Case Study 3. Delhi. GOA NULL. Jaipur Delhi 2 Goa 1 Jaipur 2 Ahmedabad 0 Mumbai 2 Bangalore 0 Destination city GOA reached. Delhi. Pune ORIG: NULL. Mumbai. 3. Student will learn how to represent the graph like structure during implementation. Mumbai. GOA NULL. Mumbai. Originating city of JAIPUR is DELHI. queues and graphs and their usage in practical application. Jaipur.

Sign up to vote on this title
UsefulNot useful