Data Structures & AlgorithmsVery hardICPC regional · Product Company SDE

Problem: Greedy graph colouring assigns colours in vertex order 0, 1, 2, 3, 4, 5, giving each vertex the smallest colour (starting at 0) not used by an already-coloured neighbour. The graph has edges 0-2, 0-3, 1-2, 1-4, 2-3, 3-5, 4-5. How many colours does greedy colouring use?

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

Correct answer: A. 3

Greedy colouring is order-dependent: each vertex takes the least colour its earlier neighbours do not use. Here the triangle 0-2-3 forces three colours, so greedy happens to match the chromatic number.

More Coding Interview Problems questions

Exams that ask this topic