Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2

Undirected graph on vertices A, B, C, D, E, F, G with edges A–B (1), B–C (1), B–D (1), B–F (1), B–G (1), C–D (1), C–F (1), D–G (1), E–F (1), E–G (1) (weights ignored). Vertices are coloured in the order A, B, C, … each with the smallest-numbered colour (0, 1, 2, …) not used by an already coloured neighbour. How many colours does this greedy colouring use?

  1. A. 5
  2. B. 4
  3. C. 6
  4. D. 3

Correct answer: B. 4

Greedy colouring in this vertex order uses 4 colours, while the chromatic number is 3. Confusing the order-dependent greedy result with the optimal value is the mistake.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic