What is a graph coloring problem?

Why Interviewers Ask This

Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.

Answer

Graph coloring assigns colors to vertices such that no two adjacent vertices share the same color, using the minimum number of colors. Chromatic number χ(G): the minimum number of colors needed. This is NP-hard in general (no polynomial algorithm for optimal coloring). Special cases: 2-colorable (Bipartite): checkable in O(V+E) with BFS/DFS — color alternately; if you need the same color for adjacent vertices, it's not bipartite; Greedy coloring: iterate vertices, assign the smallest color not used by neighbors. Not optimal but fast — uses at most Δ+1 colors (Δ = max degree); Backtracking: try each color for each vertex, backtrack if conflict — exponential worst case but works for small graphs; Welsh-Powell algorithm: sort vertices by degree descending, greedily color. Applications: (1) Register allocation in compilers (variables are nodes, conflicts are edges — minimize CPU registers needed); (2) Map coloring (four color theorem: any planar map needs ≤ 4 colors); (3) Scheduling (time slot assignment — same-time exams can't conflict); (4) Sudoku solving; (5) Frequency assignment in wireless networks. Interval graph coloring (intervals as nodes, overlapping as edges) is solvable in O(n log n) greedily.

Pro Tip

Back up your answer with a specific project or situation. Saying 'In my last Data Structures & Algorithms project, I used this when...' immediately makes your answer more credible and memorable.