Data Structures & AlgorithmsModerateGATE CS · ICPC regional
An undirected graph has the vertices M, O, U, Y and the edges U–O, U–Y, M–O, O–Y. 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
- The directed acyclic graph has the vertices B, C, K, P, Q, R, V, Z and the arcs Z→V, K→R, C→B, K→C, Q→B, Z→B, Z→K, R→V, Q→Z, P→R, K→B…
- A directed graph has the vertices C, D, F, G, H, I, Q, W and the arcs I→H, I→D, I→F, I→W, Q→D, Q→F, Q→G, Q→C, H→F, H→W, H→C, F→I, F→Q…
- A directed acyclic graph has the vertices A, D, M, O, Q, U, V and the edges U→M, U→D, U→V, Q→U, Q→O, A→M, A→V, O→U. A topological order…
- An undirected connected graph on 6 vertices has the edges (weights in brackets, all distinct): X–K (3), S–D (11), X–S (24), S–K (13), D–K…
- An undirected graph has the vertices E, F, O, P, Q and the edges Q–E, F–O, F–E, F–P, O–P, E–P. A walk may repeat vertices and edges. How…
- A directed graph has the vertices C, D, G, M, P, W and the arcs D→P, D→W, C→M, C→P, G→D, W→D, W→G. How many strongly connected components…