1. Write a program to implement the depth-first search algorithm using the pseudocode given on the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Write a program to implement the depth-first search algorithm using the pseudocode given on the next page. 2. Write a driver program, which reads input file mediumG.txt as an undirected graph and runs the depth-first search algorithm to find paths to all the other vertices considering 0 as the source. This driver program should display the paths in the following manner: 0 to 'v': list of all the vertices traversed to go to v from 0, separated by ,'. There is another file called tinyG.txt which you can use for your testing purpose. DFS (G) 1 for each vertex u € G.V 2 u.color = WHITE 3 U.π = NIL 4 5 6 7 time=0 for each vertex u € G.V if u.color == WHITE DFS-VISIT (G, u) DFS-VISIT (G, u) 1 time = time + 1 2 u.d = time u.color= GRAY for each ve G.Adj[u] 3 4 5 6 7 8 = 9 time time +1 10 u.f = time if v.color == WHITE V.π = u DFS-VISIT (G, v) u.color= BLACK // white vertex u has just been discovered // explore edge (u, v) // blacken u; it is finished 1. Write a program to implement the depth-first search algorithm using the pseudocode given on the next page. 2. Write a driver program, which reads input file mediumG.txt as an undirected graph and runs the depth-first search algorithm to find paths to all the other vertices considering 0 as the source. This driver program should display the paths in the following manner: 0 to 'v': list of all the vertices traversed to go to v from 0, separated by ,'. There is another file called tinyG.txt which you can use for your testing purpose. DFS (G) 1 for each vertex u € G.V 2 u.color = WHITE 3 U.π = NIL 4 5 6 7 time=0 for each vertex u € G.V if u.color == WHITE DFS-VISIT (G, u) DFS-VISIT (G, u) 1 time = time + 1 2 u.d = time u.color= GRAY for each ve G.Adj[u] 3 4 5 6 7 8 = 9 time time +1 10 u.f = time if v.color == WHITE V.π = u DFS-VISIT (G, v) u.color= BLACK // white vertex u has just been discovered // explore edge (u, v) // blacken u; it is finished
Expert Answer:
Answer rating: 100% (QA)
Answer 1 THE DFS is as follows import javautil public class DFS no of vertices int V we are building graph using adjacency list so we should have link... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Write a small C++ program. Your program should compile correctly and produce the specified output. Please note that the computer program should comply with the commenting and formatting rules as has...
-
From his analyst, the investor learned the following figures: One hryvnia invested in Bet Cone, on average, brings 30 kopecks of profit with a standard deviation of 10 kopecks, invested in Hair Team...
-
a) Using Smith's multiplier (1991) applies to Black's (1976) method to calculate the price of a Payer Swaption knowing the following information: - A 2-year Payer Swaption written on a 4-year Swap -...
-
How is it that a state, or any state, such as Oregon, can offer more provisions under FMLA (OFLA) than then the federal rule of FMLA does?
-
(a) What is the energy E of the hydrogen-atom electron whose probability density is represented by the dot plot of figure?(b) What minimum energy is needed to remove this electron from theatom?
-
If x1, x2,...., xn span a vector space V, then they are linearly independent.
-
A particular cyclist can produce an average power output of \(180 \mathrm{~W}\) when cycling on level ground. While doing this, their speed is \(9.5 \mathrm{~m} / \mathrm{s}\). What is the magnitude...
-
On January 4, 2014, Penman Company purchased 124,000 shares of Hi Energy Company directly from one of the founders for a price of $44 per share. Hi Energy has 400,000 shares outstanding, including...
-
When an object is placed at the focus of a concave mirror, the image formed is (i) at infinity (ii) real and inverted, and (iii) highly magnified (or highly enlarged) M E A D C B P F At infinity N
-
Congratulations! You've just been hired by a company as their new Quality Manager. They are a large manufacturer of parts for the aerospace industry. The boss sits you down on the first day and...
-
Lucas must decide how to invest $4,000. He can deposit the money in a savings account that pays simple interest at a rate of 5.25% annually, or Lucas can deposit the money in a CD accound paying...
-
In a strict liability case a. a plaintiff is not required to prove cause in fact or proximate cause. b. an act will not be considered a superseding cause of the plaintiffs injury if the act was...
-
What is foreseeable misuse?
-
True Or False Suppliers of services can be found negligent, but sellers of real estate cannot.
-
The owner of a(n) ____________ animal is strictly liable for any damage resulting from a dangerous propensity typical of that particular species.
-
True Or False Retailers have no duty to inspect goods unless they believe they may be dangerous.
-
Good X (250x, SOV (150K, 150Y) (100x, 100Y) Income-$2000, P-$10, P-$10 (50X, 250Y) Income $3000, P-$10, P-$10 The shift from the green to the blue budget line shows an increase in income. Increases...
-
Identify Thank You mission, strategy and core competencies. Identify strategy changes that have taken place at Thank You since its founding in 2008. Your answer must in text references and must be...
-
Which of the following statements is not true? a. Animation in JavaFX must be run either sequentially or in parallel. b. Timeline animation updates property values along a progression of time. c....
-
Create a class named Pizza with data fields for description (such as sausage and onion) and price. Include a constructor that requires arguments for both fields and a method to display the data....
-
The arguments required by the font constructor include all of the following except ____________. A. Typeface b. Mode c. Style d. Point size
-
Management is considering three alternatives to satisfy an urgent need. Each of the alternatives will completely satisfy the need, so no combinations have to be considered. The first costs, operating...
-
Consider the following cash flow profile, and assume MARR is 10 percent/year and the finance rate is 4 percent/year. a. Determine the MIRR for this project. b. Is this project economically...
-
Consider the following cash flow profile and assume MARR is 10 percent/year and the finance rate is 4 percent/ year. a. Determine the MIRR for this project. b. Is this project economically...
Study smarter with the SolutionInn App