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