3. Write a version of the depth-first search algorithm, where graph G is represented by an...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
3. Write a version of the depth-first search algorithm, where graph G is represented by an adjacency matrix and the output the preorder labelling of the vertices as an integer array. You can use the code on page 367 of Goodrich and Tamassia as a starting point (given in the slides). Assume the graph is simple and connected. Do not worry about labelling the edges as explored, discovery or back edges. Focus on how you would use the adjacency matrix to find adjacent vertices and how to determine if a vertex has been explored or not yet (Hint: the preorder labels may help with that.) Algorithm matrixDFS(G,v) Input: A graph G, with n vertices labeled 0, ..., n - 1, represented as an adjacency matrix and a starting vertex v. Output: An integer array of size n, containing the preorder labelling of the vertices. 4. Analyze the best-case and worst-case running times of your matrixDFS() algorithm in question 3 above. How does this compare to the best-case and worst-case running times of implementing DFS with an adjacency list representation of the graph? 3. Write a version of the depth-first search algorithm, where graph G is represented by an adjacency matrix and the output the preorder labelling of the vertices as an integer array. You can use the code on page 367 of Goodrich and Tamassia as a starting point (given in the slides). Assume the graph is simple and connected. Do not worry about labelling the edges as explored, discovery or back edges. Focus on how you would use the adjacency matrix to find adjacent vertices and how to determine if a vertex has been explored or not yet (Hint: the preorder labels may help with that.) Algorithm matrixDFS(G,v) Input: A graph G, with n vertices labeled 0, ..., n - 1, represented as an adjacency matrix and a starting vertex v. Output: An integer array of size n, containing the preorder labelling of the vertices. 4. Analyze the best-case and worst-case running times of your matrixDFS() algorithm in question 3 above. How does this compare to the best-case and worst-case running times of implementing DFS with an adjacency list representation of the graph?
Expert Answer:
Answer rating: 100% (QA)
The depthfirst search DFS algorithm using an adjacency matrix representation of the graph to find the preorder labeling of the vertices def matrixDFSG ... View the full answer
Related Book For
Artificial Intelligence Structures And Strategies For Complex Problem Solving
ISBN: 9780321545893
6th Edition
Authors: George Luger
Posted Date:
Students also viewed these programming questions
-
Current Attempt in Progress On April 1, 2024, Sunland Company purchased 35,200 common shares in Ecotown Ltd. for $13 per share. Management has designated the investment as FVTOCI. On December 5,...
-
QUIZ... Let D be a poset and let f : D D be a monotone function. (i) Give the definition of the least pre-fixed point, fix (f), of f. Show that fix (f) is a fixed point of f. [5 marks] (ii) Show that...
-
Show that every continuous function f : D D on a domain D has a least prefixed point, fix(f). [3 marks] (b) Let h : P P be a continuous function on a domain P. Show that fix(h) = fix(h h). [3 marks]...
-
Seanna OBrien receives pension payments of $3200 at the end of every six months from a retirement fund of $50 000. The fund earns 7% compounded semi-annually. (a) How many payments will Seanna...
-
Identify the etlryl groups and the methyl groups in the structure of 4-sec-butyl-5ethyl-3- methyloctane, the compound discussed in Study problem 2.5. Note that these groups are not necessarily...
-
Over the past 6 months, 90% of the births have resulted in 2-day stay at a hospital; for the remaining 10% of the cases, the average length of time in the maternity ward is 7 days. To achieve...
-
Explain how each of the following security procedures can increase system reliability: 1 Encryption 2 Employee security awareness training 3 Eirewalls 4 IDS 5 VPNs
-
Lang Company began operations on January 1, 2014, by issuing common stock for $64,000 cash. During 2014, Lang received $95,000 cash from revenue and incurred costs that required $75,000 of cash...
-
Question 10: Why should you ensure that your analysis of the internal and external environments is consistent with the perspectives of other informed people? Write your answer in 150-200 words.
-
Time left 0:46:58 f Questions 8 to 9 are based on the following information. (1 mark each) On January 1, 2020 Jomo started a small business buying and selling steering wheel covers. He invested...
-
Evaluate h'(1) where h(x) = f(x) g(x) given the following. f(1) = 5 f'(1) = -1.5 h'(1) = g(1) = 4 g'(1) = 3 Need Help? Read It
-
on the graph of Find the points f(x, y) = (x+8) (y - 9)7 at which the tangent plane is horizontal.
-
One year ago, you had acquired Tesla Inc, USA for US$50.00 per share. The current price is US$60.00 and during the year, you received 3 dividend payments totalling US$15.00. Calculate the following:...
-
solve (xy-3)+(6xy+2x - 5)
-
The lecture discussed what happens after the jury comes back with a verdict. Sometimes, it is a verdict our client is not pleased to hear, or one that still presents challenges if the opponent...
-
Widget Inc. produced 50,000 units in year 1 and had operating cash flow of $600,000 and a sales price per unit of $51.00. In year 2 unit, sales are expected to increase to 55,000. The company has a...
-
Which, if any, of the dichloroethene molecules drawn in Data Table II (3.) (4.) and (5.) are geometric isomers? A. B. C. D. cis-1,2-dichloroethene and trans-1,2-dichloroethene...
-
Dominick Portet Wines Inc. began operations to import fine wines from Australia to the United States. Sales and purchase information is pZro vided below. Assume that Portet Wines uses the LIFO method...
-
Santiago, Inc., began operations as an importer of fine Chilean wine the United States. Sales and purchase information is provided below. Santiago, Inc., uses the LIFO method of inventory valuation....
-
Presented below are the financial statements of two companies that are identical in every respect except the method of valuing their inventories. The method of valuing inventory is LIFO for the LIFO...
Study smarter with the SolutionInn App