Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B
Unweighted directed graph on vertices 0 to 6 with edges: 3→5, 5→4, 1→3, 4→0, 1→5, 0→2, 1→4, 0→1, 3→1, 2→6, 2→0, 5→6, 2→4, 2→1, 1→6. How many shortest paths (fewest edges) lead from 0 to 6? Two paths are different if their vertex sequences differ.
- A. 7
- B. 2
- C. 3
- D. 4
Correct answer: B. 2
BFS finds distance 2 and 2 shortest paths, counted level by level. Counting every simple path (7) or ignoring directions (3) are the traps; 4 vertices sit at that distance.
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 directed graph on vertices 0 to 7 has edges listed in this order: 0→1, 5→3, 3→0, 6→5, 7→6, 3→1, 2→5, 3→7, 5→4, 4→0, 6→7, 5→1, 1→0, 1→5…
- A directed graph on vertices 0 to 5 has edges listed in this order: 3→0, 4→0, 5→3, 2→5, 0→3, 2→0, 5→4, 1→3, 0→2, 2→1. A depth-first search…
- A directed graph on vertices 0 to 6 has edges listed in this order: 5→0, 2→1, 3→1, 5→3, 6→2, 1→6, 1→4, 2→6, 1→2, 2→3. A depth-first search…
- A directed graph on vertices 0 to 6 has edges listed in this order: 1→5, 4→0, 5→6, 1→0, 4→6, 5→0, 5→3, 3→5. A depth-first search visits…
- A directed graph on vertices 0 to 4 has edges listed in this order: 2→3, 1→4, 0→2, 1→3, 2→0, 1→2, 0→1, 3→1. A depth-first search visits…
- A directed graph on vertices 0 to 5 has edges listed in this order: 5→2, 5→3, 1→5, 0→1, 3→1, 1→3, 3→4, 5→4. A depth-first search visits…