Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2 B
An undirected graph on 7 vertices has the edges G–T, G–H, T–E, T–X, E–O, E–H, E–B, O–B. How many simple paths (no repeated vertex) go from G to B? Paths are counted as vertex sequences, so each route is counted once.
- A. 4
- B. 2
- C. 5
- D. 8
Correct answer: A. 4
A DFS that extends the path through unvisited neighbours enumerates every simple route, giving 4. Counting only the shortest routes gives 2, which is a much smaller set.
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 connected undirected graph has the vertices H, K, M, N, R, S, V and the edges V–H, H–S, H–K, H–N, H–M, S–R, N–M. How many bridges does…
- A connected undirected graph has the vertices N, R, U, W, Z and weighted edges (weights in brackets): W–R (7), R–N (1), U–R (16), U–Z (5)…
- An undirected graph has the vertices C, D, P, R, T, W and the edges D–T, T–W, T–P, W–P, P–C, W–C, D–P, R–P, R–C. What is the minimum…
- A connected undirected graph has the vertices C, G, O, Q, T, U and the edges G–T, G–Q, G–U, T–Q, T–C, Q–U, Q–O, Q–C, O–C. Parallel edges…
- An undirected graph has the vertices C, E, H, I, M, N, O, R, U, Y and the edges H–R, H–E, H–N, H–M, C–O, C–R, C–E, C–N, C–M, C–Y, C–I…
- A tree has the vertices D, J, K, M, O, R, U, W, Z and the edges K–Z, K–M, Z–D, M–U, D–J, D–W, D–O, K–R. A centroid is a vertex whose…