Consider the problem of finding the least expensive routes to all cities in a network from a
Question:
Consider the problem of finding the least expensive routes to all cities in a network from a given starting point. For example, in the network shown on the mapbelow, the least expensive route from Pendleton to Peoria has cost 8 (going through Pierre and Pueblo).
When the algorithm has finished, shortestKnownDistance contains the shortest distance from the starting point to all reachable targets.
Transcribed Image Text:
The following helper class expresses the distance to another city: public class Distance To implements Comparable { private String target; private int distance; public DistanceTo (String city, int dist) { target= city; distance = dist; } public String getTarget() { return target; } public int getDistance() { return distance; } public int compareTo (Distance To other) { return distance other.distance; } } All direct connections between cities are stored in a Map . The algorithm now proceeds as follows: Let from be the starting point. Add DistanceTo (from, o) to a priority queue. Construct a map shortest known Distance from city names to distances. While the priority queue is not empty Get its smallest element. If its target is not a key in shortest knownDistance Let d be the distance to that target. Put (target, d) into shortestknownDistance. For all cities c that have a direct connection from target Add DistanceTo(c, d + distance from target to c) to the priority queue.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (QA)
Based on the details and images you have provided the goal is to implement Dijkstras algorithm to find the shortest path from a starting city the first city in the input file to all other cities in th...View the full answer
Answered By
Ayush Mishra
I am a certified online tutor, with more than 3 years of experience in online tutoring. My tutoring subjects include: Physics, Mathematics and Mechanical engineering. I have also been awarded as best tutor for year 2019 in my previous organisation. Being a Mechanical Engineer, I love to tell the application of the concepts of science and mathematics in the real world. This help students to develop interest and makes learning fun and easy. This in turn, automatically improves their grades in the subject. I teach students to get prepared for college entry level exam. I also use to teach undergraduate students and guide them through their career aim.
5.00+
2+ Reviews
10+ Question Solved
Related Book For
Question Posted:
Students also viewed these Java Programming questions
-
Consider the problem of finding the least expensive routes to all cities in a network from a given starting point. For example, in the network shown on the map on page 733, the least expensive route...
-
Let i and j be positive integers. (i) Prove that there exist natural numbers a and b such that ai = bj+gcd(i, j). You may use standard results provided that you state them clearly. [4 marks] (ii) Let...
-
do the following,..... Write program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. Create program that takes in user input...
-
A new out-of-state client, Robert Ball, has asked you to prepare a Form 709 for a large gift he made in 2013. When you request copies of any prior gift tax returns he may have filed, he responds,...
-
Refrigerant-134a enters an adiabatic compressor at 15 psia and 20°F with a volume flow rate of 10 ft3/s and leaves at a pressure of 100 psia. The power input to the compressor is 45 hp. Find (a)...
-
How would you demonstrate the influence of relevant theory in your research proposal? LO5
-
Do you think globalization and MNE activity are creating problems for the world? What kinds of problems can you identify? What are the unintended consequences of international business? L01
-
When a company acts in an ethically questionable manner, what types of problems are caused for the organization and its customers?
-
Your company bought a piece of machinery for $100,000, and depreciated it using a 7 year MACRS approach. However, after 3 years your company sold the machinery for $50,000. Compute the after-tax...
-
1. Which of the two basic reporting approaches for the cash flows from operating activities did Lowes use? Is this the same as what The Home Depot used? 2. What amount of cash did Lowes receive from...
-
The linked list class in the Java library supports operations addLast and removeLast. To carry out these operations efficiently, the LinkedList class has an added reference last to the last node in...
-
Extend Exercise Business P15.12 to a program that can handle shares of multiple companies. The user enters commands buy symbol quantity price and sell symbol quantity price. Keep a Map> that manages...
-
A media prep technician operates ____________ pH _______________ SRIR plates _____________ filtration equipment, open ____________ tanks, and ___________.
-
a) Discuss whether bike paths can be considered a public good. Now consider a hypothetical town. Suppose that there are three equal-size groups in the economy with the following demand curves: Group...
-
Event services and management can be a lucrative revenue generator. What are the two most important factors in developing a successful event service and management business, whether it is independent...
-
Show how the buying process occurs in the consumer. Review some of the steps in the buying process, stories like: felt need pre-purchase activity purchase decision Post-purchase feelings Explain and...
-
How did Henry Ford set the stage for some of the same problems we still face today in employee relations, especially in manufacturing? 2) If you were a human resources manager, how would you address...
-
What does a DMO risk by not having a positioning theme? Critique the potential of your destination's slogan to effectively differentiate against rivals. you have been asked by a television network to...
-
To convene a formal meeting with the investor group, you need to first draft a report that outlines the types of franchise opportunities you'd like to pursue. Write a brief report, identifying five...
-
Give an example of transitory income. What effect does this income have on the marginal propensity to consume?
-
In a cellular system, with omni-directional antennas, employs a cluster of size 7. The cell at the center of the cluster has much more traffic than the others and need to borrow some channels from...
-
What are the advantages of cell sectoring? How do you compare this with SDMA?
-
In a cellular system, with 7-cell clusters, has the following average number pf calls at a given time: Cell number Average number of calls/unit time...
-
please help Problem 13-7 (Algo) Prepare a Statement of Cash Flows [LO13-1, LO13-2] [The following information applies to the questions displayed below.] Comparative financial statements for Weaver...
-
A firm has 1000 shareholders, each of whom own $59 in shares. The firm uses $28000 to repurchase shares. What percentage of the firm did each of the remaining shareholders own before the repurchase,...
-
Vancouver Bank agrees to lend $ 180,000 to Surrey Corp. on November 1, 2020 and the company signs a six-month, 6% note maturing on May 1, 2021. Surrey Corp. follows IFRS and has a December 31 fiscal...
Study smarter with the SolutionInn App