Data Structures & AlgorithmsHardGATE CS · ICPC regional
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 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 back edges are there?
- A. 4
- B. 0
- C. 6
- D. 1
Correct answer: D. 1
Following the listed order gives tree 4, back 1, forward 0, cross 6 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 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…
- Connected simple undirected graph on vertices 0 to 8 with edges: 2–5, 5–6, 3–5, 3–4, 0–1, 1–4, 5–7, 7–8, 4–6. How many bridges does it…
- Directed flow network on vertices 0 to 4 (source 0, sink 4) with capacities (u→v (c)): 4→1 (5), 1→2 (5), 0→1 (10), 0→3 (1), 4→0 (7), 2→3…
- Directed flow network on vertices 0 to 5 (source 0, sink 5) with capacities (u→v (c)): 2→0 (6), 0→3 (3), 0→5 (9), 4→1 (9), 0→1 (6), 2→4…