BFS to find distances For a given set of digraphs, write a program that performs BFS...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
BFS to find distances For a given set of digraphs, write a program that performs BFS on each digraph starting at node 0 and prints the distance to the most distant node and reports the node with the lowest index at that distance. Nodes that are not reachable from 0 have an undefined distance and should be ignored. Digraph input format A sequence of one or more digraphs is taken from the keyboard (System.in). Each graph is represented by an adjacency list. The first line is an integer n indicating the order of the graph. This is followed by n white space separated lists of adjacencies for nodes labeled 0 to n - 1. The lists are sorted. The input will be terminated by a line consisting of one zero (0). This line should not be processed. The sample input below shows two digraphs, the first has node set {0, 1,2,3} and arc set {(0, 1), (0, 3), (1, 2), (1, 3), (2,0)}, the second has node set {0, 1, 2} and arc set {(0, 1), (0, 2), (2, 1)}. 4120 13 23 3 12 1 0 Output format: For each input digraph, print out a line with the distance to the most distant node, then a comma, then the lowest index of a node at that distance. Ignore nodes that are not reachable from 0. For the example input shown below, the output would be 2,2 1,1 BFS to find distances For a given set of digraphs, write a program that performs BFS on each digraph starting at node 0 and prints the distance to the most distant node and reports the node with the lowest index at that distance. Nodes that are not reachable from 0 have an undefined distance and should be ignored. Digraph input format A sequence of one or more digraphs is taken from the keyboard (System.in). Each graph is represented by an adjacency list. The first line is an integer n indicating the order of the graph. This is followed by n white space separated lists of adjacencies for nodes labeled 0 to n - 1. The lists are sorted. The input will be terminated by a line consisting of one zero (0). This line should not be processed. The sample input below shows two digraphs, the first has node set {0, 1,2,3} and arc set {(0, 1), (0, 3), (1, 2), (1, 3), (2,0)}, the second has node set {0, 1, 2} and arc set {(0, 1), (0, 2), (2, 1)}. 4120 13 23 3 12 1 0 Output format: For each input digraph, print out a line with the distance to the most distant node, then a comma, then the lowest index of a node at that distance. Ignore nodes that are not reachable from 0. For the example input shown below, the output would be 2,2 1,1
Expert Answer:
Answer rating: 100% (QA)
Here is an example of a Python program that performs BFS on a given digraph starting at node 0 and p... View the full answer
Related Book For
Thermodynamics An Engineering Approach
ISBN: 978-0073398174
8th edition
Authors: Yunus A. Cengel, Michael A. Boles
Posted Date:
Students also viewed these programming questions
-
1.Write a python script that takes an input file and creates a 2 dimensional array Then performs the following FUNCTIONS. ALL HAVE TO BE FUNCTION AND INTERACT and work based on an interface....
-
Write a function that takes an input file stream object and a 2d array as parameters and reads all the characters in the input file stream, incrementing the count in the 2d array for each letter found
-
Using the information in Table and assuming only Na+ and Ca 2+ are present and the SAR = 1, calculate the TDS (mg/L) and ECw, of the solution represented by 10 mmolc L-1 on the x-axis scale in Figure.
-
Select only 2. Two questions which can be used to address ethical issues impacting organizations and Human Resource Management include: What would my Supervisor say? Does this behavior or result meet...
-
Employees at Whites Department Store are observed engaging in the following behavior: (1) They hide items that are on sale from the customers and (2) they fail to expend appropriate effort in...
-
Can the police and community be truly effective in forming a partnership to reduce juvenile delinquency? Discuss the role of the juvenile police officer in preventing and investigating juvenile crime.
-
Northern Group, Inc., is a Wisconsin corporation that contracts with manufacturers and suppliers to develop marketing strategies and promotions to third-party retailers. In exchange for these...
-
ABC, wholesale, customer profitability Ramirez Wholesalers operates at capacity and sells furniture items to four department-store chains (customers). Mr. Ramirez commented, "We apply ABC to...
-
35. Expandiendo e sin en serie de Fourier en wt, mostrar que la ecuacin trascendedente de Kepler tiene la solucin formal: = wt+Jn(ne) sin (wt), n=1 n 2 donde J, es la funcin de Bessel de orden n....
-
1. Assuming Anson decided to charge barrel costs (but not warehousing and aging costs) to inventory, what 2012 income statement and balance sheet items would change, and what would the new amounts...
-
1. How would you define leadership? 2. Not all effective leaders seems to be reflective by nature. How do you reconcile that with the concept of the spiral of experience and its role in leadership...
-
Estimate the binary diffusion coefficient for a ethanenitrogen mixture containing 60 mol% ethane at 310 K amd 60 atm absolute pressure. First, estimate the diffusivity at 1 atm. Then, use the...
-
A silica-based catalyst particle has a porosity p = 0.60. Estimate its thermal conductivity at 25C if the pores are (a) filled with air at 1 atm and (b) filled with liquid water.
-
An open tank, 3.0 m in diameter, contains liquid benzene at 37C exposed to air also at 37C and 1 atm absolute pressure. Assume that the rate of evaporation is controlled by diffusion through a...
-
It is March 13th and you just left the beach with your friends carrying along great memories of a fabulous Spring break. As your thoughts drift from sun-drenched beaches to mass transfer problems,...
-
A spherical naphthalene ball with an initial diameter of 1.2 cm slowly sublimes in a large volume of still air at 15C and 1 atm. At this temperature, the sublimation pressure of naphthalene is 0.036...
-
X Ltd. has net income for tax purposes of $120,000 and taxable income of $90,000. The net income includes $8,000 of taxable Canadian dividends, $7,000 taxable capital gains, and $9,000 interest...
-
Write the binomial probability in words. Then, use a continuity correction to convert the binomial probability to a normal distribution probability. P(x 110)
-
A room contains 75 kg of air at 100 kPa and 15C. The room has a 250-W refrigerator (the refrigerator consumes 250 W of electricity when running), a 120-W TV, a 1.8-kW electric resistance heater, and...
-
A solar cell has an open circuit voltage value of 0.60 V with a reverse saturation current density of Jo 5 4.11 3 1010 A/ft2. (a) For a temperature of 75oF, determine the load voltage at which the...
-
The thrust developed by the engine of a Boeing 777 is about 380 kN. Assuming choked flow in the nozzles, determine the mass flow rate of air through the nozzle. Take the ambient conditions to be 220...
-
Which of the following criticisms expressed by Ryan about the use of historical data is the least valid? A. In a context of hyperinflation, the approach may not be appropriate. B. The companies...
-
1. Assume the S&P 500 forward earnings yield is 5 percent and the 10-year T-note yield is 4.6 percent. Are stocks overvalued or undervalued according to the Fed model? 2. Why might the earnings yield...
-
Data from which Tobins q and equity q can be calculated are published in the Flow of Funds Accounts of the United States-Z.1, published quarterly by the Federal Reserve.* This data source is...
Study smarter with the SolutionInn App