Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
An undirected graph has the vertices E, F, G, I, Z and the edges G–I, G–Z, G–F, E–F, I–Z, I–F, Z–F. A walk may repeat vertices and edges. How many walks of length exactly 3 go from G to E?
- A. 30
- B. 2
- C. 5
- D. 1
Correct answer: B. 2
The (i, j) entry of the k-th power of the adjacency matrix counts walks of length k, giving 2. Simple paths from G to E give only 5, and walks of length 2 give 1.
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
- An undirected graph on 5 vertices has the edges D–E, D–J, D–T, E–H, E–J, E–T, H–T, J–T. How many simple paths (no repeated vertex) go from…
- The directed acyclic graph has the vertices D, F, G, I, J, O, Z and the arcs J→D, I→G, G→F, I→Z, I→D, F→D, G→D. How many distinct directed…
- A connected undirected graph has the vertices D, E, O, P, W and weighted edges (weights in brackets): D–P (3), E–P (19), D–E (8), P–O (5)…
- A bipartite graph has left side P1, P2, P3 and right side Q1, Q2, Q3, Q4, Q5, with edges P3–Q1, P1–Q2, P3–Q2, P3–Q4, P1–Q5, P2–Q4, P1–Q1…
- A grid has 4 rows and 3 columns with these values (top to bottom): 944 176 815 649 A path moves between side-adjacent cells (up, down…
- A tree has vertices with values in brackets: R[-3], G[6], I[7], U[-4], H[3], W[1], P[9], O[-3]. The edges are R–G, G–I, I–U, R–H, R–W…