Lecture from: 11.03.2025 | Video: Homelab

k-Coloring and Chromatic Number

Definition of k-Coloring

A k-coloring of a graph is an assignment of colors to the vertices of such that no two adjacent vertices share the same color. Formally, a k-coloring is a function , where represents the set of colors, such that for every edge , we have .

In simpler terms, we are painting each vertex with one of colors so that connected vertices always have different colors.

Chromatic Number

The chromatic number of a graph , denoted by , is the minimum number of colors required to properly color the vertices of . In other words, is the smallest integer for which a k-coloring of exists.

k-Partite Graphs and Chromatic Number

A graph is k-partite if its vertex set can be partitioned into disjoint sets such that no edge in connects two vertices within the same set . An equivalent formulation for the chromatic number is:

if and only if is k-partite.

Each set in the k-partition represents a set of vertices that can all be colored with the same color without violating the coloring condition. These sets are also known as stable sets or independent sets, meaning they contain no edges within themselves.

Special Case: Bipartite Graphs

A special case of k-partite graphs is when . A graph is bipartite if and only if it is 2-colorable, i.e., . We can efficiently determine if a graph is bipartite and find a 2-coloring (if one exists) in time using Breadth-First Search (BFS) or Depth-First Search (DFS). If a connected graph is bipartite, it contains no odd cycles.

Applications of Graph Coloring

Graph coloring is not just a theoretical concept; it has numerous practical applications in various fields. Here are a few examples:

Examination Timetabling

Imagine we need to schedule exams for several students. Some students are taking multiple courses, so certain exams cannot be scheduled at the same time to avoid conflicts for students. We can model this problem using graph coloring:

  • Vertices: Each vertex represents an exam.
  • Edges: An edge between two vertices exists if there is at least one student taking both exams (meaning they cannot be scheduled at the same time).
  • Colors: Each color represents a timeslot or exam period.

A valid graph coloring assigns timeslots to exams such that no conflicting exams are scheduled at the same time. The goal is to minimize the number of timeslots (colors) needed, which corresponds to finding the chromatic number of the graph.

Register Allocation in Compilers

In computer science, register allocation is a crucial step in compiling code. Registers are small, fast storage locations within a CPU. Variables frequently used in a program should ideally be stored in registers to speed up execution. However, the number of registers is limited.

We can use graph coloring to allocate registers efficiently:

  • Vertices: Each vertex represents a variable in the program.
  • Edges: An edge between two variables exists if they are “live” at the same time and thus interfere with each other (cannot be assigned to the same register).
  • Colors: Each color represents a register.

A valid graph coloring assigns registers to variables such that interfering variables are assigned different registers. Minimizing the number of registers (colors) used is the objective. This is known as interference graph coloring.

Frequency Assignment in Wireless Networks

In wireless communication, different frequencies are used to avoid interference between signals. Consider a network of wireless transmitters (e.g., base stations in a cellular network or nodes in a sensor network). Transmitters that are geographically close or whose signals can interfere need to operate on different frequencies.

Graph coloring can model this frequency assignment problem:

  • Vertices: Each vertex represents a wireless transmitter.
  • Edges: An edge between two transmitters exists if their signals can interfere with each other.
  • Colors: Each color represents a frequency band.

A valid graph coloring assigns frequencies to transmitters such that interfering transmitters use different frequencies. Minimizing the number of frequencies (colors) used is important to conserve the frequency spectrum.

Map Coloring and the Four-Color Theorem

A famous problem in graph theory is map coloring. Imagine a map of countries or states. We want to color each region such that no two adjacent regions (sharing a border) have the same color.

This can be represented as a graph:

  • Vertices: Each vertex represents a region.
  • Edges: An edge between two regions exists if they share a border.
  • Colors: Colors are used to color the regions.

The Four-Color Theorem states that any planar map (and therefore any planar graph) can be colored with at most four colors. This theorem has a long history and was famously proven using computer assistance.

Why is Graph Coloring So Hard?

Despite its seemingly simple definition, graph coloring is computationally challenging in general. Let’s briefly touch upon why this is the case.

Colorability is Computationally Hard

While graph coloring has many applications, determining the chromatic number of a graph or even just checking if a graph is k-colorable for is computationally difficult. For it’s a trivial check, since we need to alternate colors.

Graphs with High Chromatic Number and No Short Cycles

Theorem: For any integers and , there exist graphs that do not contain any cycles of length (i.e., they are locally tree-like) but have a chromatic number of at least .

This theorem demonstrates that a graph can be locally sparse (resembling a tree locally) yet still require a large number of colors for proper vertex coloring. This is counterintuitive because sparse graphs often have small chromatic numbers. The proof for is given in the lecture script.

This property highlights that global constraints of graph coloring, rather than just local structure, make the problem hard. Just because a graph looks locally simple (like a tree) does not imply that it’s easy to color globally.

NP-Completeness

Theorem: For every fixed integer , the problem of determining whether a given graph is k-colorable (i.e., whether ) is NP-complete.

This NP-completeness result implies that, unless P=NP, there is no polynomial-time algorithm to solve the k-coloring problem for . This makes finding optimal graph colorings for general graphs very challenging for larger instances.

Approximation Hardness

Not only is finding the exact chromatic number NP-hard, but even approximating it is also hard.

Approximation Hardness Result: For every , it is NP-hard to approximate the chromatic number within a factor of , where is the number of vertices.

This means that finding an algorithm that always produces a coloring using at most colors for some constant , or even within a factor of of the chromatic number, is unlikely to be possible in polynomial time (unless P=NP).

Exponential Algorithms

Despite the NP-hardness, we can still find exact solutions using exponential-time algorithms. One such approach is based on inclusion-exclusion and dynamic programming. This algorithm can determine the chromatic number of a graph using polynomial space and time , which is better than brute-force checking of all possible color assignments ( for k colors).

Special Cases and Heuristics

Due to the computational hardness of general graph coloring, research often focuses on:

  • Special Classes of Graphs: Finding efficient coloring algorithms for specific types of graphs, such as planar graphs, perfect graphs, interval graphs, etc.
  • Approximation Algorithms: Designing algorithms that provide colorings that are “good enough” (though constant-factor approximations are hard in general, as mentioned).
  • Heuristics: Developing practical algorithms that may not guarantee optimality or performance bounds but work well in practice for many instances.

Greedy Coloring Algorithm

A simple and widely used approach for graph coloring is the Greedy Coloring Algorithm. It is a heuristic algorithm, meaning it doesn’t guarantee to find an optimal coloring (a coloring using colors), but it is often effective in practice and easy to implement.

Algorithm Description

GREEDY-COLORING (G):

  1. Choose a Vertex Ordering: Select an arbitrary ordering of the vertices . The performance of the greedy algorithm can depend significantly on this ordering.

  2. Initialize Colors: Assign color 1 to the first vertex in the ordering, .

  3. Iterate Through Vertices: For each vertex from to :

    • Find Available Colors: Consider the neighbors of that have already been colored (i.e., neighbors in the set ).
    • Choose the Smallest Available Color: Assign to the smallest positive integer color that is not already used by any of its neighbors in . Formally:

Performance of Greedy Coloring

Observation 1: Upper Bound on Colors Used

For any vertex ordering, the Greedy Coloring Algorithm never uses more than colors, where is the maximum degree of the graph .

Explanation: When we color vertex , it has at most neighbors in the entire graph, and thus at most neighbors that have already been colored (from ). Therefore, there is always at least one color available from that is not used by its already-colored neighbors.

Notation: (maximum degree in ).

Observation 2: Best-Case Performance

There exists a vertex ordering for which the Greedy Coloring Algorithm uses exactly colors. This means that for some orderings, the greedy algorithm can find an optimal coloring.

Explanation: Consider an optimal coloring of that uses colors. We can order the vertices such that vertices of color 1 come first, then vertices of color 2, and so on, up to color . When we apply the greedy algorithm with this ordering, each vertex will be assigned a color no greater than its optimal color, and thus the algorithm will use at most colors (and at least by definition). Note that finding this sort of ordering is equivalent and equally hard.

Observation 3: Worst-Case Performance

There exist bipartite graphs (which have ) and vertex orderings for which the Greedy Coloring Algorithm uses colors. This demonstrates that for some graphs and orderings, the greedy algorithm can perform quite poorly compared to the optimal chromatic number.

Example: Consider a complete bipartite graph (where is even). In a worst-case ordering, the greedy algorithm might color vertices in a way that it uses a new color for every vertex in one partition, resulting in colors, even though the chromatic number is 2.

Heuristics for Vertex Ordering in Greedy Coloring

The choice of vertex ordering is crucial for the performance of the Greedy Coloring Algorithm. A good ordering can often lead to colorings that are closer to optimal. One common and effective heuristic is the smallest-last ordering (also known as reverse Cuthill-McKee ordering in some contexts, though slightly different):

Smallest-Last Vertex Ordering Heuristic:

  1. Find Minimum Degree Vertex: Find a vertex with the minimum degree in the current graph.
  2. Remove and Recurse: Remove and all incident edges from the graph. Recursively find a smallest-last ordering for the remaining graph. Let this ordering be .
  3. Reverse Order: The smallest-last ordering for the original graph is .

In essence, we repeatedly pick a vertex of minimum degree in the remaining graph, remove it, and place it last in the ordering. This heuristic tends to place low-degree vertices towards the end, giving them more color choices when they are colored by the greedy algorithm.

Observation about Smallest-Last Ordering:

If for a given graph and the smallest-last vertex ordering , it holds that for every , the number of neighbors of in is at most (i.e., ), then the Greedy Coloring Algorithm using this ordering will use at most colors.

Why smallest-last heuristic works well:

The smallest-last ordering tends to create a situation where, when we color a vertex , it has relatively few already-colored neighbors. This increases the chances of finding a small color index that is available, thus reducing the total number of colors used.

Trees and Planar Graphs

  • Trees: For trees, the smallest-last ordering (or even a simple BFS or DFS ordering) used with the Greedy Coloring Algorithm will always produce a 2-coloring (which is optimal since trees are bipartite, except for ).

  • Planar Graphs: It is known (though without proof here) that in every planar graph, there exists a vertex of degree at most 5. If we apply the smallest-last vertex ordering heuristic to a planar graph, it is likely that for each vertex , it will have at most 5 neighbors among . Therefore, using the Greedy Coloring Algorithm with the smallest-last ordering on a planar graph typically uses at most 6 colors. While the 4-Color Theorem guarantees that 4 colors are always sufficient for planar graphs, the greedy algorithm with this heuristic often performs reasonably well in practice.

Corollary: For a connected graph , if there exists a vertex with degree , then using the smallest-last ordering (or even BFS/DFS ordering), the Greedy Coloring Algorithm will use at most colors. This is a slight improvement over the general bound.

Block Graphs and Coloring

Finally, let’s briefly mention block graphs. A block in a graph is a maximal 2-connected subgraph (or a bridge or an isolated vertex). Block graphs have a tree-like structure in terms of their blocks.

Property of Block Graphs and Coloring:

If a graph is such that every block in can be colored with colors, then the entire graph can also be colored with colors.

Algorithm Idea for Coloring Block Graphs:

  1. Color Blocks Individually: Color each block of with colors.
  2. Handle Articulation Points: Blocks can share vertices, specifically articulation points (cut vertices). When coloring blocks, we need to ensure consistency in colors assigned to articulation points. We can achieve this by potentially performing color interchanges (permutations of color classes) within blocks to ensure that when we move from one block to an adjacent block (sharing an articulation point), the coloring remains valid at the articulation point.

By carefully coloring blocks and managing colors at articulation points, we can extend k-colorings of individual blocks to a k-coloring of the entire block graph. This is a useful technique for simplifying the coloring problem for certain types of graphs by breaking them down into smaller, more manageable components (blocks).

Continue here: 08 Five-Color Theorem, Brooks Theorem, 3-Colorable Coloring Approximation, Randomness