Question

For your second co-op you are developing the next state-of-the- art flight search engine. You have...

For your second co-op you are developing the next state-of-the- art flight search engine. You have the list of all n daily flights in the world.

1. For each flight you have starting city, destination city, and price (a positive number).

Give an efficient algorithm to compute the cheapest trip from start city to end city t . You can use any number of flights in your trip.

2. Same as part 1, but if multiple trips with the same cost exist, the algorithm should find the trip with the least number of flights. You can assume that the cost of each flight is an integer >0.

3. Each flight is operated by exactly one of two airline companies

A and B. One of your customers is on an impartial federal trip, and cannot favor any airline over the other. Give an efficient algorithm to compute the cheapest trip from start city s to end city t such that no two consecutive flights are from the same airline. You can use any number of flights in the trip.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

We have starting city, destination city and price for travel between starting city and the destination city.

1. We have to find out the cheapest travel path from starting city to destination city.

     Let us take a directed graph.
     Cities will be represented by vertices and price will be the weight of edge between the vertices.

    So, this problem reduces to Dijkastra's shortest path algorithm.
    Dijkastra's algorithm finds shortest path cost from source to all other vertices. We will stop Dijkastra's algorithm when we have found out the cheapest path from source to destination city.

Algorithm:

1. Create a treeSet : Initially empty. It will contain all those vertices whose minimum cost from the source has been calculated.
2. Initially, all cost of the edges will be set to infinite and the cost of source vertex will be 0 so that it is selected as the source vertex.
3. Now, a loop till treeSet does not include the destination vertex.
             Steps in loop : i. Select the vertex x which has minimum cost from source. If it is not already added to the treeSet, add it to the treeSet.
ii. Now, update cost of all vertices which are connected to this x. Now, for all           adjacent vertices, update their cost if it is less than the sum of cost from source vertex and the cost of edge between x and the adjacent vertex.


2. In this part, we will have to keep the count of total number of vertices traversed to reach the destination.

     Dijkastra's algorithm finds shortest path cost from source to all other vertices. This time we will not stop when we reach destination.

Algorithm:

1. Create a treeSet : Initially empty. It will contain all those vertices whose minimum cost from the source has been calculated.
2. Initially, all cost of the edges will be set to infinite and the cost of source vertex will be 0 so that it is selected as the source vertex. Also, all vertex_traversed_count will be set to infinite except the source vertex.
3. Now, a loop till treeSet has all vertices.
             Steps in loop : i. Select the vertex x which has minimum cost from source. If it is not already added to the treeSet, add it to the treeSet.
ii. Now, update cost of all vertices which are connected to this x. Now, for all    adjacent vertices, update their cost if it is less than the sum of cost from source    vertex and the cost of edge between x and the adjacent vertex. Also, for all vertices    update the vertex_traversed_count i.e., how many vertices did one needs to
                                       traverse for reaching this vertex from the source vertex.
Finally, from among multiple shortest paths, path having lower vertex_traversed_count will be chosen.

3. In this part, for the sake of distinguishing the paths operated by A and B airlines, we will keep all path prices of A airline as negative and for B as positive. Negative cost is only for distinguishing between airline A and B. For calculation of cost we will take mod of the negative values.

Algorithm:

1. Create a treeSet : Initially empty. It will contain all those vertices whose minimum cost from the source has been calculated.
2. Initially, all cost of the edges will be set to infinite and the cost of source vertex will be 0 so that it is selected as the source vertex.
3. Now, a loop till treeSet does not include the destination vertex.
             Steps in loop : i. Select the vertex x which has minimum cost from source. If it is not already added to the treeSet, add it to the treeSet.
ii. Now, update cost of all vertices which are connected to this x. Now, for all adjacent vertices, update their cost if it is less than the sum of cost from source vertex and the cost of edge between x and the adjacent vertex. (Only those adjacent
          vertex will be selected whose representational cost is different from previous ones.
                                        Like if came from negative cost vertex, we will include only positive cost vertex as
adjacent vertex.)                        

                              

Add a comment
Know the answer?
Add Answer to:
For your second co-op you are developing the next state-of-the- art flight search engine. You have...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 5. You are designing a flight scheduler for a travel service such as Expedia. A passenger will re...

    Please show work clearly. Thanks! 5. You are designing a flight scheduler for a travel service such as Expedia. A passenger will request a departure time and departure city, D, C, and an arrival time and arrival city A, CA You wll have access to a list of flights, F1.. .Fn, each with an origin city, departure time, destination city, arrival time, and cost. You want to find the flights that will allow the passenger to leave CD no earlier...

  • A test specification provides designers with what needs to be known in order to perform a...

    A test specification provides designers with what needs to be known in order to perform a specific test, and to validate and verify the requirement to be tested. The test script is divided into the test script, which is the generic condition to be tested, and one or more test cases within the test script. Provide a test script and test case for at least 3 of your requirements identified in your requirements specification. Provide the following format for an...

  • Suppose you have a set of classes to schedule among a large number of lecture halls,...

    Suppose you have a set of classes to schedule among a large number of lecture halls, where any class can class place in any lecture hall. Each class cj has a start time sj and finish time fj. We wish to schedule all classes using as few lecture halls as possible. Verbally describe an efficient greedy algorithm to determine which class should use which lecture hall at any given time. What is the running time of your algorithm?

  • There are n trading posts numbered 1 to n as you travel downstream. At any trading...

    There are n trading posts numbered 1 to n as you travel downstream. At any trading post i you can rent a canoe to be returned at any of the downstream trading posts j, where j >= i. You are given an array R[i, j] defining the costs of a canoe which is picked up at post i and dropped off at post j, for 1 ≤ i ≤ j ≤ n. Assume that R[i,i] = 0 and that you...

  • IT CAN ALSO BE INDIVIDUAL) Purpose: The purpose of this exercise is to give you practice...

    IT CAN ALSO BE INDIVIDUAL) Purpose: The purpose of this exercise is to give you practice in developing a test to measure one specific ability for the job of airline reservation clerk for a major airline. If time permits, you’ll be able to combine your tests into a test battery. Required Understanding: Your airline has decided to outsource its reservation jobs to Asia. You should be fully acquainted with the procedure for developing a personnel test and should read the...

  • You are a brick layer, and you're trying to build a wall out of bricks. Each...

    You are a brick layer, and you're trying to build a wall out of bricks. Each brick i has height 1 but can have variable length Li . At every step, someone hands you a brick & you have the option of either adding it to the current layer of bricks or starting a new layer of bricks on top of the old layer. Once you start a new layer of bricks, you can't add bricks to lower layers. Each...

  • Problem 6. (20 points) Texting. You are competing with your friends to type text messages on your...

    the pseudocode or precise description in words of the algorithm Problem 6. (20 points) Texting. You are competing with your friends to type text messages on your smartphone as quickly as possible. Here are the rules: you use two thumbs for texting and they start out on the bottom left and bottom right keys of the keyboard. To type a character, you move either thumb from its current key to the key you need to press, and it takes time...

  • PLEASE MAKE SURE TO ANSWER PART 2 AND 3. YOU DON'T HAVE TO WORRY ABOUT PART...

    PLEASE MAKE SURE TO ANSWER PART 2 AND 3. YOU DON'T HAVE TO WORRY ABOUT PART 1, I ALREADY GOT IT PART 1 Part 1: Please read the business statement below and draw ER, NER, and Table Schema diagrams for it. You can submit your diagrams as a Dia file or an image file (GIF, JPG, or PNG). Business Statement: The project is about developing an auction Web site. The details are as follows: BA is an online auction Web...

  • What happened on United flight 3411?What service expectations do customers have of airlines such ...

    What happened on United flight 3411?What service expectations do customers have of airlines such as United and How did these expectations develop over time? Thank You! In early April 2017, United Airlines (United), one of the largest airlines in the world, found itself yet again in the middle of a service disaster this time for forcibly dragging a passenger off an overbooked flight. The incident was to become a wake-up call for United, forcing it to ask itself what to...

  • ND-OF-CHAPTER QUESTIONS Thought Questions 1. How do you think TCP would handle the problem if an ...

    ND-OF-CHAPTER QUESTIONS Thought Questions 1. How do you think TCP would handle the problem if an acknowledgment were lost, so that the sender retrans- mitted the unacknowledged TCP seg- ment, therefore causing the receiving transport process to receive the same segment twice? 2-2. a) Compute the minimum number of TCP segments required to open a con- nection, send an HTTP request and response message, and close the con- nection. Justify this number by creating a table showing each message and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT