Question

In: Computer Science

Let G be a graph whose vertices are the integers 1 through 8, and let the...

  1. Let G be a graph whose vertices are the integers 1 through 8, and let the adjacent vertices of each vertex be given by the table below:

vertex

adjacent vertices

1

(2, 3, 4)

2

(1, 3, 4)

3

(1, 2, 4)

4

(1, 2, 3, 6)

5

(6, 7, 8)

6

(4, 5, 7)

7

(5, 6, 8)

8

(5, 7)

Assume that, in a traversal of G, the adjacent vertices of a given vertex are returned in the same order as they are listed in the above table.

  1. Order the vertices as they are visited in a DFS traversal starting at vertex 1.

  2. Order the vertices as they are visited in a BFS traversal starting at vertex 1.

Solutions

Expert Solution

Answer:-


(1) Order the vertices as they are visited in a DFS traversal starting at vertex 1.

We use the following steps to implement DFS traversal...

  • Step 1 - Define a Stack of size total number of vertices in the graph.
  • Step 2 - Select any vertex as starting point for traversal. Visit that vertex and push it on to the Stack.
  • Step 3 - Visit any one of the non-visited adjacent vertices of a vertex which is at the top of stack and push it on to the stack.
  • Step 4 - Repeat step 3 until there is no new vertex to be visited from the vertex which is at the top of the stack.
  • Step 5 - When there is no new vertex to visit then use back tracking and pop one vertex from the stack.
  • Step 6 - Repeat steps 3, 4 and 5 until stack becomes Empty.
  • Step 7 - When stack becomes Empty, then produce final spanning tree by removing unused edges from the graph

After applying above STEPS the DFS values are as follws:-

DFS: 1-2-3-4-6-5-7-8

(2) Order the vertices as they are visited in a BFS traversal starting at vertex 1.

We use the following steps to implement BFS traversal...

  • Step 1 - Define a Queue of size total number of vertices in the graph.
  • Step 2 - Select any vertex as starting point for traversal. Visit that vertex and insert it into the Queue.
  • Step 3 - Visit all the non-visited adjacent vertices of the vertex which is at front of the Queue and insert them into the Queue.
  • Step 4 - When there is no new vertex to be visited from the vertex which is at front of the Queue then delete that vertex.
  • Step 5 - Repeat steps 3 and 4 until queue becomes empty.
  • Step 6 - When queue becomes empty, then produce final spanning tree by removing unused edges from the graph.

After applying above STEPS the BFS values are as follws:-

BFS: 1-2-3-4-6-5-7-8


Related Solutions

Problem 8. A bipartite graph G = (V,E) is a graph whose vertices can be partitioned...
Problem 8. A bipartite graph G = (V,E) is a graph whose vertices can be partitioned into two (disjoint) sets V1 and V2, such that every edge joins a vertex in V1 with a vertex in V2. This means no edges are within V1 or V2 (or symbolically: ∀u, v ∈ V1, {u,v} ∉ E and ∀u,v ∈ V2, {u,v} ∉ E). 8(a) Show that the complete graph K2 is a bipartite graph. 8(b) Prove that no complete graph Kn,...
Let G be a bipartite graph with 107 left vertices and 20 right vertices. Two vertices...
Let G be a bipartite graph with 107 left vertices and 20 right vertices. Two vertices u, v are called twins if the set of neighbors of u equals the set of neighbors of v (triplets, quadruplets etc are defined similarly). Show that G has twins. Bonus: Show that G has triplets. What about quadruplets, etc.?
Let Q:= {1,2,...,q}. Let G be a graph with the elements of Q^n as vertices and...
Let Q:= {1,2,...,q}. Let G be a graph with the elements of Q^n as vertices and an edge between (a1,a2,...,an) and (b1,b2,...bn) if and only if ai is not equal to bi for exactly one value of i. Show that G is Hamiltonian.
let G be a simple graph. show that the relation R on the set of vertices...
let G be a simple graph. show that the relation R on the set of vertices of G such that URV if and only if there is an edge associated with (u,v) is a symmetric irreflexive relation on G
2. Let G be a bipartite graph with 10^7 left vertices and 20 right vertices. Two...
2. Let G be a bipartite graph with 10^7 left vertices and 20 right vertices. Two vertices u, v are called twins if the set of neighbors of u equals the set of neighbors of v (triplets, quadruplets etc are defined similarly). Show that G has twins. Show that G has triplets. What about quadruplets, etc.? 3. Show that there exists a bipartite graph with 10^5 left vertices and 20 right vertices without any twins. 4. Show that any graph...
Let G be a simple undirected graph with n vertices where n is an even number....
Let G be a simple undirected graph with n vertices where n is an even number. Prove that G contains a triangle if it has at least (n^2 / 4) + 1 edges using mathematical induction.
Let G a graph of order 8 with V (G) = {v1, v2, . . ....
Let G a graph of order 8 with V (G) = {v1, v2, . . . , v8} such that deg vi = i for 1 ≤ i ≤ 7. What is deg v8? Justify your answer. Please show all steps thank you
Question 1 a) Prove that if u and v are distinct vertices of a graph G,...
Question 1 a) Prove that if u and v are distinct vertices of a graph G, there exists a walk from u to v if and only if there exists a path (a walk with distinct vertices) from u to v. b) Prove that a graph is bipartite if and only if it contains no cycles of odd length. Please write legibly with step by step details. Many thanks!
You are given a directed graph G(V,E) with n vertices and m edges. Let S be...
You are given a directed graph G(V,E) with n vertices and m edges. Let S be the subset of vertices in G that are able to reach some cycle in G. Design an O(n + m) time algorithm to compute the set S. You can assume that G is given to you in the adjacency-list representation.
Let Kn denote the simple graph on n vertices. (a) Let v be some vertex of...
Let Kn denote the simple graph on n vertices. (a) Let v be some vertex of Kn and consider K n − v, the graph obtained by deleting v. Prove that K n − v is isomorphic to K n−1 . (b) Use mathematical induction on n to prove the following statement: K n , the complete graph on n vertices, has n(n-1)/2 edges
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT