Data Structures & AlgorithmsHardGATE CS · ICPC regional
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 visits out-neighbours in the order their edges are listed, starts at 0 and then starts from the smallest unvisited vertex each time. Each edge is classified as tree (to an unvisited vertex), back (to a vertex still on the recursion stack), forward (to an already finished descendant) or cross (to any other finished vertex). How many cross edges are there?
- A. 2
- B. 4
- C. 3
- D. 1
Correct answer: A. 2
Following the listed order gives tree 4, back 3, forward 1, cross 2 edges. The other three classes are the classic mix-ups with the requested type.
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 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…
- A directed graph on vertices 0 to 7 has edges listed in this order: 3→7, 4→0, 7→3, 3→0, 3→4, 6→7, 6→4, 7→5, 6→5, 4→3, 4→6, 1→3, 0→1, 5→4…
- A directed graph on vertices 0 to 5 has edges listed in this order: 2→0, 4→2, 3→4, 2→1, 5→0, 3→0, 5→1, 5→2, 2→5, 3→2. A depth-first search…
- A directed graph on vertices 0 to 5 has edges listed in this order: 1→0, 2→0, 4→2, 4→3, 3→0, 3→2, 3→5, 0→1. A depth-first search visits…