Data Structures & AlgorithmsModerateGATE CS · ICPC regional
An undirected graph has the vertices C, P, T, X and the edges T–P, C–P, C–X, P–X. In how many ways can each vertex be given one of 3 colours (colours are labelled, and no two adjacent vertices may share a colour)?
- A. 24
- B. 81
- C. 12
- D. 13
Correct answer: C. 12
Count the proper 3-colourings by backtracking over the vertices; there are 12. Forgetting the edges gives 81, and subtracting each edge's monochromatic colourings once (no overlaps) gives -27.
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
- Cities B, C, F, T, U are joined by roads with these travel costs: B–U 20, B–T 13, B–C 7, B–F 17, U–T 4, U–C 9, U–F 2, T–C 11, T–F 6, C–F…
- A tree has vertices with weights in brackets: E[6], C[8], O[8], B[11], X[14], D[9], T[5], M[1]. The edges are E–C, C–O, E–B, B–X, X–D…
- Bellman–Ford is run from source O on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: L→O…
- Cities C, F, G, N, Q, X are joined by roads with these travel costs: C–Q 20, C–X 13, C–N 2, C–F 11, C–G 6, Q–X 8, Q–N 15, Q–F 13, Q–G 12…
- An undirected graph has the vertices J, M, N, Q, R, S, W and the edges R–N, M–Q, Q–J, Q–W, M–S, M–R, Q–R, Q–S, M–J, R–S. How many simple…
- A connected undirected graph has the vertices B, D, I, N, O, P, Z and the edges I–P, I–B, I–Z, I–N, P–N, P–O, B–D, Z–N. How many bridges…