Data Structures & AlgorithmsHardIBM · Deloitte pattern
An undirected graph has adjacency lists (neighbours visited in alphabetical order) A: [D, F]; B: [C, F]; C: [B, E]; D: [A, E]; E: [C, D]; F: [A, B]. What is the (recursive) DFS traversal order starting from A?
- A. A, B, C, D, E, F
- B. F, B, C, E, D, A
- C. A, D, E, C, B, F
- D. A, D, F, E, B, C
Correct answer: C. A, D, E, C, B, 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, D, E, C, B, F. BFS from the same start would instead explore level by level, giving A, D, F, E, B, C.
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
- Keys 93, 67, 60, 15, 3, 58, 52, 13, 92 are inserted via separate chaining (h(k) = k mod 7, new keys appended to the end of the chain) into…
- Build a binary min-heap in place from the array [35, 63, 89, 24, 71, 8, 16, 88, 2, 79] using bottom-up heapify (sift-down from the last…
- A binary tree has preorder traversal [52, 25, 42, 27, 64, 92, 78] and inorder traversal [25, 27, 42, 52, 64, 78, 92]. Reconstructing the…
- Keys 45, 55, 65 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- Keys 56, 48, 53, 36, 81, 29, 64 are inserted via separate chaining (h(k) = k mod 7, new keys appended to the end of the chain) into a…
- A binary tree has preorder traversal [72, 40, 18, 19, 54, 47, 92, 81] and inorder traversal [18, 19, 40, 47, 54, 72, 81, 92]…