Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
An undirected graph on 6 vertices has the edges E–Z, E–K, E–W, Z–K, Z–F, Z–H, Z–W, K–F, K–W. How many simple paths (no repeated vertex) go from E to W? Paths are counted as vertex sequences, so each route is counted once.
- A. 1
- B. 7
- C. 3
- D. 9
Correct answer: B. 7
A DFS that extends the path through unvisited neighbours enumerates every simple route, giving 7. Counting only the shortest routes gives 1, 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 directed graph with no directed cycles has arcs u→v (weight) : T→C (8), T→G (-3), T→L (5), C→G (1), C→X (-1), C→L (5), G→X (-3), X→L…
- A directed acyclic graph has the vertices A, B, D, G, H, I, L and the arcs H→G, H→D, H→B, H→I, H→L, A→G, A→D, A→B, A→I, A→L, G→D, G→B…
- A grid has 4 rows and 3 columns with these values (top to bottom): 855 818 192 153 A path moves between side-adjacent cells (up, down…
- A directed graph with no directed cycles has arcs u→v (weight) : U→J (2), U→K (4), J→S (0), J→K (4), S→K (-1), P→K (3). Weights may be…
- A four-wheel combination lock shows four digits 0–9 on wheels that wrap around (9 goes to 0 and 0 goes to 9). One move turns one wheel by…
- A directed graph has the vertices A, E, F, M, N, R and the arcs R→F, R→M, A→M, M→R, M→A, E→F, E→N. How many strongly connected components…