Data Structures & AlgorithmsVery hardProduct-company MCQ pattern
An undirected graph has adjacency lists (neighbours visited in alphabetical order) A: [C, E, F]; B: [C, E]; C: [A, B, F]; D: [F]; E: [A, B, F]; F: [A, C, D, E]. What is the (recursive) DFS traversal order starting from A?
- A. A, C, E, F, B, D
- B. D, F, E, B, C, A
- C. A, B, C, D, E, F
- D. A, C, B, E, F, D
Correct answer: D. A, C, B, E, F, D
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, C, B, E, F, D. BFS from the same start would instead explore level by level, giving A, C, E, F, B, D.
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
- An undirected graph has adjacency lists (neighbours visited in alphabetical order) A: [B, C, F]; B: [A, C, D]; C: [A, B]; D: [B, E, F]; E…
- What are the time complexities of P and Q? c int P(int n) { if (n <= 1) return 1; return P(n/2) + P(n/2) + n; } int Q(int n) { if (n <= 1)…
- Undirected graph edges: E–D, E–C, A–C, D–C, B–A, B–E, B–D. Using a BFS 2-colouring, is this graph bipartite?
- Keys 69, 79, 89 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- Keys 4, 74, 93, 84, 37, 87, 63 are inserted via separate chaining (h(k) = k mod 7, new keys appended to the end of the chain) into a table…
- Keys 79, 74, 70, 89, 2, 6, 8 are inserted via separate chaining (h(k) = k mod 7, new keys appended to the end of the chain) into a table…