Write the pseudocode of the Depth First Search Algorithm DFS(G) using adjacency-matrix representation of the graph G. What is the running time of your pseudocode? Specification: start from the psedocode discussed in class and do only the modifications needed for adjacency-matrix graph representation.
Added by Erika B.
Close
Step 1
Create a function DFS(G) that takes the adjacency matrix representation of the graph G as input. Show more…
Show all steps
Your feedback will help us improve your experience
Robert Fox and 88 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
DFS(G) 1 for each vertex u in G.V 2 u.color = WHITE 3 u.π = NIL 4 time = 0 5 for each vertex u in G.V 6 if u.color == WHITE 7 DFS-VISIT(G, u) DFS-VISIT(G, u) 1 time = time + 1 // white vertex u has just been discovered 2 u.d = time 3 u.color = GRAY 4 for each v in G.Adj[u] // explore edge (u, v) 5 if v.color == WHITE 6 v.π = u 7 DFS-VISIT(G, v) 8 u.color = BLACK // blacken u; it is finished 9 time = time + 1 10 u.f = time
Akash M.
Find the spanning tree resulting from the depth-first search algorithm applied to the connected graph below, with the given ordering of vertices. List the vertices in the order they are added to the tree and sketch the resulting tree. Find the spanning tree resulting from the breadth-first search algorithm applied to the graph above; presenting the answer as in Problem 3.
Madhur L.
Show that we can use a depth-first search of an undirected graph G to identify the connected components of G, and that the depth-first forest contains as many trees as G has connected components. More precisely, show how to modify depth-first search so that it assigns to each vertex v an integer label v.cc between 1 and k, where k is the number of connected components of G, such that u.cc = v.cc if and only if u and v are in the same connected component.
Ishana K.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Watch the video solution with this free unlock.
EMAIL
PASSWORD