Data Structures & AlgorithmsHardGATE CS · ICPC regional · Product Company SDE
An undirected graph has adjacency lists A:BC B:ADE C:ADE D:BC E:BC. Neighbours are always explored in alphabetical order. Which is the DFS (recursive, pre-order) visiting order starting at A?
- A. ECDBA
- B. ABDCE
- C. ACEBD
- D. ABCDE
Correct answer: B. ABDCE
Alphabetical neighbour order. DFS goes as deep as possible before backtracking giving ABDCE.
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
- How many different spanning trees does the complete graph K7 have (Cayley's formula)?
- Keys 12, 98, 23, 44, 16, 38, 41, 70 are inserted one by one into an empty binary search tree. What is the post-order traversal?
- An undirected graph has edges (u–v: weight) A–B:16, B–C:7, C–D:13, A–E:1, C–F:25, A–C:12, B–F:22, E–D:4. What is the weight of its minimum…
- In the undirected graph with edges A–B:2, A–C:3, A–D:5, C–E:3, E–F:8, F–A:2, what is the shortest-path distance from A to B?
- An undirected graph has adjacency lists A:BCDF B:AC C:AB D:AE E:D F:A. Neighbours are always explored in alphabetical order. Which is the…
- Keys 37, 18, 57, 76, 72, 36, 64, 21 are inserted in this order into an empty BST. What is the height of the tree (edges on the longest…