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