Data Structures & AlgorithmsHardGATE CS · ICPC regional
A directed graph on vertices 0 to 6 has edges listed in this order: 1→6, 3→1, 3→5, 4→2, 0→4, 0→1, 5→4, 4→6, 0→2, 1→2, 2→5, 0→3, 1→0. 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 forward edges are there?
- A. 1
- B. 6
- C. 2
- D. 4
Correct answer: A. 1
Following the listed order gives tree 6, back 2, forward 1, cross 4 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: 6→5, 1→0, 2→3, 0→2, 3→0, 2→6, 4→3, 1→5, 5→6, 2→5. A depth-first search…
- A directed graph on vertices 0 to 4 has edges listed in this order: 0→4, 1→2, 1→0, 0→3, 0→1, 1→3, 3→1. A depth-first search visits…
- A directed graph on vertices 0 to 7 has edges listed in this order: 7→0, 3→6, 1→4, 7→4, 2→0, 4→2, 6→3, 6→2, 5→3, 4→6, 7→6. A depth-first…
- A directed graph on vertices 0 to 4 has edges listed in this order: 2→4, 3→4, 0→1, 3→2, 2→3, 3→1, 2→0, 0→4. A depth-first search visits…
- A directed graph on vertices 0 to 6 has edges listed in this order: 1→2, 1→6, 3→1, 0→3, 6→3, 3→6, 6→0, 3→5, 6→5, 4→5, 0→5. A depth-first…
- Connected simple undirected graph on vertices 0 to 7 with edges: 5–6, 5–7, 4–5, 0–1, 2–5, 1–6, 0–6, 0–3. How many bridges does it have…