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
-
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...
-
Give a general balanced reaction for The complete combustion of a cycloalkane containing one ring formula CnH2n.
-
Find the elements of the variance-covariance matrix for the one way model in the case where n i = n for all i.
-
A parallel-plate capacitor in which the plates are extendable is connected to a battery and charged until there is a charge \(+q\) on one plate and a charge \(-q\) on the other plate. (a) With the...
-
Triangle Utilities provides electricity for three cities. The company has four electric generators that are used to provide electricity. The main generator operates 24 hours per day, with an...
-
1. 49 The value of n(n+n+1) is equal to (10a) [10a-3. The value of (a + ) is n=1 48 47 46 2 1 2. If + + + + + = (2)(3) (3)(4) (4)(5) (48)(49) (49)+(50) k is equal to 3. +++++ Then 4. 5. In a...
-
Peoria Corp. just completed another successful year, as indicated by the following income statement: Presented here are comparative balance sheets: Other information is as follows: a. Dividends of...
-
You just made a trip home and are visiting with your dad. He is 59 years old and has spent the past 12 years working in various management positions for Target. Prior to that, he served 20 years in...
-
People are sometimes puzzled by the fact that entrepreneurs who have made millions of dollars still put in 60- to 80-hour weeks helping their companies innovate and grow. After reading the chapter,...
-
Discuss the theory of constraints and that approach to scheduling.
-
Give examples of commonly used priority rules.
-
Describe scheduling needs in job shops.
-
Based on the data below answer these questions: a) What is the total duration of the project? b) Which activities are part of the critical path? c) What are the Cost Performance Index (CPI) and...
-
Do public and private companies follow the same set of accounting rules? Explain.
-
The lightweight wheel on a road bike has a moment of inertia of 0.097 kg m 2 . A mechanic, checking the alignment of the wheel, gives it a quick spin; it completes 5 rotations in 2.0 s. To bring the...
-
The engine in a small airplane is specified to have a torque of 500 N m. This engine drives a 2.0-m-long, 40 kg single-blade propeller. On startup, how long does it take the propeller to reach 2000...
-
We can model a small merry-go-round as a uniform circular disk with mass 88 kg and diameter 1.8 m. How many 22 kg children need to ride the merry-go-round, standing right at the outer edge, to double...
Study smarter with the SolutionInn App