chapter
    Graph Traversal: BFS and DFS PYQs for GATE DA

    Solve 4+ Graph Traversal: BFS and DFS previous year questions for GATE DA with answers and detailed solutions. Free sample questions below.

    Try a question

    Answer it here to see how it works. Nothing is recorded until you sign in.

    Question 1
    2026 PYQ
    Level 3: Exam Standard
    Consider a directed graph , where is the finite set of vertices and is the set of directed edges between the vertices. may contain cycles but there is no self-loop. Further, may not be strongly connected.

    Let be the graph obtained by reversing the directions of all the edges in without changing the set of vertices.

    Assume that Breadth First Search (BFS) or Depth First Search (DFS) from any given vertex of a graph visits only the reachable vertices from in that graph.

    Which of the following statements must always be true, regardless of the structure of ?
    Question 2
    2025 PYQ
    Level 3: Exam Standard
    Consider a directed graph , where and . Suppose the adjacency list of each vertex is in decreasing order of vertex number, and depth-first search (DFS) is performed at vertex . The number of vertices that will be discovered after vertex is
    (Answer in integer)
    Question 3
    2025 PYQ
    Level 3: Exam Standard
    Question 4
    2024 PYQ
    Level 3: Exam Standard
    Consider performing depth-first search (DFS) on an undirected and unweighted
    graph starting at vertex . For any vertex in , is the length of the shortest
    path from to . Let be an edge in such that . If the edge
    is explored first in the direction from to during the above DFS, then
    becomes a ______ edge.
    Free preview ends here

    Login to view the complete previous-year questions and solutions

    Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.

    Why MastersUp

    Personalised first. High quality throughout.

    Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.

    Built around you, not around a syllabus PDF

    Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.

    Revision that hits your weak spots

    We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.

    Questions calibrated to the real exam

    Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.

    Notes written for recall, not for volume

    Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.

    One place for everything

    Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.

    Honest progress

    No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.

    Unlock the whole course

    Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.

    Graph Traversal: BFS and DFS PYQs for GATE DA

    Solve 4+ Graph Traversal: BFS and DFS previous year questions for GATE DA with answers and detailed solutions. Free sample questions below.

    Chapter Roadmap: Graph Traversal

    Chapter Roadmap: Graph Traversal

    1. Reachability in Directed Graphs Forward and reverse reachability, SCCs 2. DFS Discovery and Edge Classification Tree edges, back edges, cross edges 3. Graph Traversal on Given Diagrams Visual tracing and structural properties

    What you will master

    • How directed edges break the symmetry of connectivity.
    • Using reverse graphs to find strongly connected components.
    • Classifying edges discovered during Depth First Search.
    • Accurately tracing traversals on complex visual diagrams.

    Reachability in Directed Graph Traversals

    Reachability in Directed Graph Traversals

    Understanding how one-way edges change the fundamental nature of graph exploration.

    The Core Shift

    In an undirected graph, a traversal from a source vertex naturally discovers its entire connected component. The path can be traversed in both directions.

    In a directed graph, edges are one-way streets. A traversal from vertex only discovers vertices that are reachable from by following the directed edges. It does not guarantee that those discovered vertices can reach back to .

    Graph Traversal: BFS and DFS: Solved Questions with Step-by-Step Explanations (4 Problems)

    Question 1 · Programming, Data Structures and Algorithms · 2026 MCQ
    Consider a directed graph , where is the finite set of vertices and is the set of directed edges between the vertices. may contain cycles but there is no self-loop. Further, may not be strongly connected.

    Let be the graph obtained by reversing the directions of all the edges in without changing the set of vertices.

    Assume that Breadth First Search (BFS) or Depth First Search (DFS) from any given vertex of a graph visits only the reachable vertices from in that graph.

    Which of the following statements must always be true, regardless of the structure of ?
    1. A.

      If is a reachable vertex in the BFS of from , then is also a reachable vertex in the DFS of from .

    2. B.

      In , the BFS traversal from will visit exactly the same set of vertices as the DFS from in .

    3. C.

      The order of vertices visited in the BFS of from is the reverse of the order of vertices visited in the DFS of from .

    4. D.

      If is a reachable vertex in the DFS of from , then is also a reachable vertex in the BFS of from .

    Correct Answer:

    D

    Step-by-Step Solution

    Insight: BFS/DFS on from finds exactly the set of vertices that can reach in . BFS/DFS on from finds exactly the set of vertices reachable from in .

    Exam route: Translate each option into reachability language in .

    Learning route:

    1. Let = vertices reachable from in . This is what DFS/BFS on from returns.
    2. Let = vertices that can reach in . This is what DFS/BFS on from returns.
    3. Option A: . False. Counter-example: only. can reach but cannot reach .
    4. Option B: . False. Same counter-example.
    5. Option C: BFS order is reverse of DFS order. False. BFS is level-by-level, DFS is deep-first; no reason for reversal.
    6. Option D: in in .

    If is reachable from in , there is a path .

    Reversing all edges gives in .

    So is reachable from in . This is exactly in (which is computed by BFS on from ).

    True.

    Answer: D.

    Question 2 · Programming, Data Structures and Algorithms · 2025 NAT
    Consider a directed graph , where and . Suppose the adjacency list of each vertex is in decreasing order of vertex number, and depth-first search (DFS) is performed at vertex . The number of vertices that will be discovered after vertex is
    (Answer in integer)
    Correct Answer:

    75.00

    Step-by-Step Solution

    Insight: With adjacency lists in decreasing order, DFS from 0 always jumps to before , creating a deep chain of even vertices up to 100, then backtracking to fill in the odd vertices in reverse order.

    Exam route: Trace the first few steps to spot the pattern, then count mathematically.

    Learning route:

    1. Edges from go to and (since ).
    2. Decreasing order means we visit before .
    3. DFS trace:
    • Visit 0. Go to 2. Go to 4. ... Go to 100. (All evens in increasing order.)
    • At 100, no unvisited neighbors. Backtrack to 98.
    • 98's next neighbor is 99. Visit 99. 99's only neighbor is 100 (visited). Backtrack.
    • 96's next neighbor is 97. Visit 97. Backtrack.
    • ... continue down: 95, 93, ..., 51.
    • Backtrack past 50 to 48. 48's next neighbor is 49. Visit 49. Backtrack.
    • Continue: 47, 45, ..., 1.
    1. Discovery order:
    • Phase 1 (evens up): 0, 2, 4, ..., 100. (51 vertices)
    • Phase 2 (odds down from 99): 99, 97, ..., 51. (25 vertices)
    • Phase 3 (odds down from 49): 49, 47, ..., 1. (25 vertices)
    1. Vertex 50 is the 26th vertex discovered (0 is 1st, 2 is 2nd, ..., 50 is 26th).
    2. Vertices discovered after 50 = Total vertices - 26 = 101 - 26 = 75.

    Answer: 75.

    Question 3 · Programming, Data Structures and Algorithms · 2025 MSQ
    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    ["A","B","D"]

    Step-by-Step Solution

    Defect notice: The question statement and the graph diagram are missing from the printed PYQ. Based on the options and the topic (Graph Traversal on Given Diagrams), this is reconstructed as the classic GATE-style question asking which of the listed edges are cross edges in a DFS traversal of a specific visual graph starting from a root vertex.

    Insight: A cross edge in DFS connects two vertices that are neither ancestors nor descendants of each other — their discovery/finish intervals are completely disjoint.

    Exam route: Trace the DFS on the assumed standard diagram, record discovery and finish times for every vertex, then apply the timestamp test (disjoint intervals) to each candidate edge.

    Learning route:

    1. Reconstruct the likely graph: vertices through , with edges forming a structure where DFS from produces a spanning tree and several non-tree edges.
    2. Perform DFS, strictly following the adjacency list order (usually alphabetical or as drawn).
    3. For each candidate edge, check if the destination was already fully finished when the source examined it.
    4. : is in a different branch from 's subtree → cross edge.
    5. : is in a separate branch → cross edge.
    6. : is typically a descendant or in 's own subtree in the standard diagram → not a cross edge (often a forward or tree edge).
    7. : is in a disjoint branch from → cross edge.

    Answer: , , are cross edges.

    Question 4 · Programming, Data Structures and Algorithms · 2024 MCQ
    Consider performing depth-first search (DFS) on an undirected and unweighted
    graph starting at vertex . For any vertex in , is the length of the shortest
    path from to . Let be an edge in such that . If the edge
    is explored first in the direction from to during the above DFS, then
    becomes a ______ edge.
    1. A.

      tree

    2. B.

      cross

    3. C.

      back

    4. D.

      gray

    Correct Answer:

    A

    Step-by-Step Solution

    Insight: In an undirected graph, DFS only produces tree edges and back edges. If and we explore from to (meaning is unvisited), it must be a tree edge.

    Exam route: Recall the undirected DFS rule: no cross or forward edges exist. Since is unvisited when explored from , it's a tree edge by definition.

    Learning route:

    1. The graph is undirected and unweighted. is the shortest path distance from to .
    2. In undirected DFS, every edge is either a tree edge or a back edge. (Forward and cross edges are impossible.)
    3. "Explored first in the direction from to " means when examines , is unvisited, so DFS traverses to .
    4. By definition, an edge to an unvisited vertex is a tree edge.
    5. The condition is consistent: if is a tree edge, is a child of , so . Since , we have .
    6. Could it be a back edge? If were a back edge, would be an ancestor of , meaning was visited before . But the problem says the edge is explored from to first, implying was unvisited. Contradiction.

    Answer: tree (A).

    More previous year questions (pyqs) in this unit