Data Structures & AlgorithmsModerateCodeforces Div 2 C · GATE CS
An undirected graph has the vertices D, M, P, Q, Y and the edges Q–P, Q–D, P–M, P–Y, M–D. A walk may repeat vertices and edges. How many walks of length exactly 3 go from Q to P?
- A. 5
- B. 7
- C. 0
- D. 9
Correct answer: A. 5
The (i, j) entry of the k-th power of the adjacency matrix counts walks of length k, giving 5. Simple paths from Q to P give only 2, and walks of length 2 give 0.
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
- Starting from the integer 6, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- A tree has the vertices E, F, G, I, K, N, Y and the edges G–F, G–N, F–E, N–K, K–Y, K–I. A centroid is a vertex whose removal leaves no…
- An undirected graph on 7 vertices has the edges J–P, J–O, J–U, P–O, P–B, P–U, O–S, O–A, O–U, A–U. How many simple paths (no repeated…
- Grid with 4 rows and 4 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .G.. G.G. .... .... Each step, which is a…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→E (6), S→A (2), S→C (2), S→T (6), E→T (2), D→A…
- A directed graph has the vertices D, E, H, I, K, N, O and the arcs N→E, N→D, K→N, K→O, E→O, I→N, I→E, H→K, O→N. How many strongly…