Wednesday, July 3, 2024
HomeData ModellingData Structure & AlgorithmAlgorithms | Graph Traversals | Question 12

Algorithms | Graph Traversals | Question 12

Let G be an undirected graph. Consider a depth-first traversal of G, and let T be the resulting depth-first search tree. Let u be a vertex in G and let v be the first new (unvisited) vertex visited after visiting u in the traversal. Which of the following statements is always true? (GATE CS 2000)

(A)

{u,v} must be an edge in G, and u is a descendant of v in T

(B)

{u,v} must be an edge in G, and v is a descendant of u in T

(C)

If {u,v} is not an edge in G then u is a leaf in T

(D)

If {u,v} is not an edge in G then u and v must have the same parent in T

Answer: (C)
Explanation:

In DFS, if \'v\' is visited
after \'u\', then one of the following is true.
1) (u, v) is an edge.
     u
   /   \\
  v     w
 /     / \\
x     y   z

2) \'u\' is a leaf node.
     w
   /   \\
  x     v
 /     / \\
u     y   z 

In DFS, after visiting a node, we first recur for all unvisited children. If there are no unvisited children (u is leaf), then control goes back to parent and parent then visits next unvisited children.

Hence (C) is the correct answer.

Quiz of this Question
Please comment below if you find anything wrong in the above post

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments