Data Structures & AlgorithmsHardGATE CS · Advanced
A graph has the vertices A–G and the edges A–B, A–C, A–D, B–D, B–F, B–G, C–D, C–F, C–G, D–F, E–F. In how many ways can the vertices be coloured with three available colours (red, green, blue, all distinguishable) so that adjacent vertices differ? Not every colour has to be used.
- A. 30
- B. 8
- C. 24
- D. 4
Correct answer: C. 24
Brute-force the 3^7 assignments (or use deletion-contraction): exactly 24 proper colourings. Dividing by 3! counts only unlabelled colour classes, and by 3 fixes one vertex's colour.
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
- Floyd-Warshall is run on a directed graph with vertices 1-6 and arcs (weights): 1→2 (9), 1→3 (8), 1→4 (8), 1→5 (1), 2→5 (3), 2→6 (8), 3→1…
- A flow network has source S = A and sink T = G (vertices A–G) with arcs and capacities: A→D (1), A→E (6), A→G (6), B→C (2), B→E (5), C→F…
- How many structurally different binary search trees can be built on the keys 1, 2, ..., 8 (all distinct shapes, one per key set) whose…
- A rooted tree has the vertices A–M with root A, given by parents: A is the parent of B, B is the parent of C, B is the parent of D, B is…
- A weighted undirected graph on A–H has the edges (weights): A–D (16), A–E (22), A–F (26), A–G (5), A–H (4), B–C (9), B–H (23), C–D (13)…
- Keys 45, 25, 65, 15, 35, 55, 75, 30 are inserted in this order into an empty binary search tree. What is its postorder traversal?