Data Structures & AlgorithmsVery hardHCLTech · Wipro pattern
An undirected graph has adjacency lists (neighbours visited in alphabetical order) A: [B, C, G]; B: [A, E, G]; C: [A, G]; D: [F, G]; E: [B]; F: [D]; G: [A, B, C, D]. What is the (recursive) DFS traversal order starting from A?
- A. A, B, C, D, E, F, G
- B. A, B, E, G, C, D, F
- C. F, D, C, G, E, B, A
- D. A, B, C, G, E, D, F
Correct answer: B. A, B, E, G, C, D, F
Recursive DFS from A immediately recurses into the first unvisited neighbour before trying the next one, diving as deep as possible before backtracking, giving A, B, E, G, C, D, F. BFS from the same start would instead explore level by level, giving A, B, C, G, E, D, F.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A disjoint-set (union-find with union by rank and path compression) over 7 elements (0 to 6), each initially its own component, runs this…
- Keys 55, 65, 75 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- Keys 4, 49, 97, 15, 7, 96, 24, 50 are inserted in this order into an empty BST. Using the BST-specific LCA algorithm (walk down from the…
- Keys 38, 28, 18 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- An undirected graph has edges (u–v: weight) A–C:16, B–C:30, C–D:17, A–D:2, A–B:3, B–D:12. What is the weight of its minimum spanning tree?
- Undirected graph edges: C–D, D–B, C–B, A–C, A–B, A–D. Using a BFS 2-colouring, is this graph bipartite?