Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional
Undirected graph on vertices A, B, C, D, E, F, G with edges A–E (1), A–G (1), B–C (1), B–E (1), B–F (1), C–F (1), C–G (1), D–E (1), D–G (1), E–G (1), F–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?
- A. 4
- B. 3
- C. 5
- D. 6
Correct answer: A. 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.
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
- Consider the recursive function def f(n): if n < 3: return 1; return f(n-1) + f(n-3). Evaluate f(11) and count every invocation of f…
- 4 × 5 grid, rows top to bottom ('#' = blocked, '.' = open): ..#.. / ..#.. / ..... / ...#.. Count the paths from top-left to bottom-right…
- Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between…
- On an 7 × 7 chessboard with rows and columns numbered 0 to 6, a knight starts at (0, 3) and must reach (5, 2) (as (row, column)). A knight…
- Distinct keys [27, 2, 19, 11, 24, 4] are inserted, in the order given by the sequence [24, 11, 4, 19, 2, 27], into an empty binary search…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (2), A–D (2), A–E (1), B–D (3), B–E (2), C–E (1). An edge is CRITICAL…