Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
An undirected graph has the vertices D, M, R, V and the edges M–D, M–V, M–R, D–V, D–R, V–R. A walk may repeat vertices and edges. How many walks of length exactly 4 go from M to D?
- A. 7
- B. 20
- C. 81
- D. 5
Correct answer: B. 20
The (i, j) entry of the k-th power of the adjacency matrix counts walks of length k, giving 20. Simple paths from M to D give only 5, and walks of length 3 give 7.
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
- The directed acyclic graph has the vertices A, B, C, G, J, O and the arcs J→C, G→C, J→O, J→A, G→A, J→B, B→C, O→B. How many distinct…
- A tree has vertices with weights in brackets: T[6], C[15], K[8], Z[3], U[2], V[2], N[14], G[14], F[1], H[7]. The edges are T–C, T–K, K–Z…
- The directed acyclic graph has the vertices D, E, J, L, N, Q, S, Z and the arcs D→Q, Z→N, N→Q, Q→S, D→J, E→S, L→Q, E→Q, D→N, E→N, J→Q…
- A connected undirected graph has the vertices A, D, E, F, H, J, M, Z and the edges J–Z, J–D, J–F, J–M, Z–F, Z–H, Z–E, D–A, D–F, A–E, F–E…
- On an 8×8 chessboard, rows and columns are numbered 0 to 7, and squares are written (row, column). A knight moves in the usual L-shape…
- An undirected graph has the vertices C, D, E, L, M, S, U and the edges U–E, U–S, U–C, D–L, D–C, D–M, L–S, L–M, E–S, E–M, C–M. What is the…