Data Structures & AlgorithmsHardGATE CS · ICPC regional
Undirected graph on vertices A, B, C, D, E, F, G with edges A–C (1), A–D (1), B–C (1), B–G (1), C–D (1), C–F (1), C–G (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?
- A. 4
- B. 5
- C. 3
- 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
- Array A = [9, 3, 7, 1, 7, 4, 3]. Over all non-empty contiguous subarrays, what is the maximum value of the XOR of the elements in the…
- A binary trie of 6-bit numbers stores the set S = [61, 52, 1, 25, 43, 9, 48]. For the query x = 45, what is the maximum value of x XOR s…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–C (1), A–D (1), B–C (1), B–D (1), B–E (1), B–F (1), B–G (1), C–D (1)…
- Weighted tree on vertices 0 to 5 with edges 0–1 (3), 0–2 (1), 1–3 (2), 1–4 (9), 2–5 (6). What is the largest possible sum of edge weights…
- Tree with vertices 0 to 7, root 0, edges 0–1, 1–2, 2–3, 0–4, 2–5, 2–6, 4–7 (parent–child). Vertex weights (vertex:weight) 0:8, 1:6, 2:7…
- Bipartite graph with left side {A, B, C, D}, right side {E, F, G, H} and edges A–G, B–F, B–G, C–E, C–H, D–E. What is the size of a maximum…