Greedy coloring

Last updated

Two greedy colorings of the same crown graph using different vertex orders. The right example generalises to 2-colorable graphs with n vertices, where the greedy algorithm expends n/2 colors. Greedy colourings.svg
Two greedy colorings of the same crown graph using different vertex orders. The right example generalises to 2-colorable graphs with n vertices, where the greedy algorithm expends n/2 colors.

In the study of graph coloring problems in mathematics and computer science, a greedy coloring or sequential coloring [1] is a coloring of the vertices of a graph formed by a greedy algorithm that considers the vertices of the graph in sequence and assigns each vertex its first available color. Greedy colorings can be found in linear time, but they do not, in general, use the minimum number of colors possible.

Contents

Different choices of the sequence of vertices will typically produce different colorings of the given graph, so much of the study of greedy colorings has concerned how to find a good ordering. There always exists an ordering that produces an optimal coloring, but although such orderings can be found for many special classes of graphs, they are hard to find in general. Commonly used strategies for vertex ordering involve placing higher-degree vertices earlier than lower-degree vertices, or choosing vertices with fewer available colors in preference to vertices that are less constrained.

Variations of greedy coloring choose the colors in an online manner, without any knowledge of the structure of the uncolored part of the graph, or choose other colors than the first available in order to reduce the total number of colors. Greedy coloring algorithms have been applied to scheduling and register allocation problems, the analysis of combinatorial games, and the proofs of other mathematical results including Brooks' theorem on the relation between coloring and degree. Other concepts in graph theory derived from greedy colorings include the Grundy number of a graph (the largest number of colors that can be found by a greedy coloring), and the well-colored graphs, graphs for which all greedy colorings use the same number of colors.

Algorithm

The greedy coloring for a given vertex ordering can be computed by an algorithm that runs in linear time. The algorithm processes the vertices in the given ordering, assigning a color to each one as it is processed. The colors may be represented by the numbers and each vertex is given the color with the smallest number that is not already used by one of its neighbors. To find the smallest available color, one may use an array to count the number of neighbors of each color (or alternatively, to represent the set of colors of neighbors), and then scan the array to find the index of its first zero. [2]

In Python, the algorithm can be expressed as:

deffirst_available(color_list):"""Return smallest non-negative integer not in the given list of colors."""color_set=set(color_list)count=0whileTrue:ifcountnotincolor_set:returncountcount+=1defgreedy_color(G,order):"""Find the greedy coloring of G in the given order.    The representation of G is assumed to be like https://www.python.org/doc/essays/graphs/    in allowing neighbors of a node/vertex to be iterated over by "for w in G[node]".    The return value is a dictionary mapping vertices to their colors."""color=dict()fornodeinorder:used_neighbour_colors=[color[nbr]fornbrinG[node]ifnbrincolor]color[node]=first_available(used_neighbour_colors)returncolor

The first_available subroutine takes time proportional to the length of its argument list, because it performs two loops, one over the list itself and one over a list of counts that has the same length. The time for the overall coloring algorithm is dominated by the calls to this subroutine. Each edge in the graph contributes to only one of these calls, the one for the endpoint of the edge that is later in the vertex ordering. Therefore, the sum of the lengths of the argument lists to first_available, and the total time for the algorithm, are proportional to the number of edges in the graph. [2]

An alternative algorithm, producing the same coloring, [3] is to choose the sets of vertices with each color, one color at a time. In this method, each color class is chosen by scanning through the vertices in the given ordering. When this scan encounters an uncolored vertex that has no neighbor in , it adds to . In this way, becomes a maximal independent set among the vertices that were not already assigned smaller colors. The algorithm repeatedly finds color classes in this way until all vertices are colored. However, it involves making multiple scans of the graph, one scan for each color class, instead of the method outlined above which uses only a single scan. [4]

Choice of ordering

Different orderings of the vertices of a graph may cause the greedy coloring to use different numbers of colors, ranging from the optimal number of colors to, in some cases, a number of colors that is proportional to the number of vertices in the graph. For instance, a crown graph (a graph formed from two disjoint sets of n/2 vertices {a1, a2, ...} and {b1, b2, ...} by connecting ai to bj whenever ij) can be a particularly bad case for greedy coloring. With the vertex ordering a1, b1, a2, b2, ..., a greedy coloring will use n/2 colors, one color for each pair (ai, bi). However, the optimal number of colors for this graph is two, one color for the vertices ai and another for the vertices bi. [5] There also exist graphs such that with high probability a randomly chosen vertex ordering leads to a number of colors much larger than the minimum. [6] Therefore, it is of some importance in greedy coloring to choose the vertex ordering carefully.

Good orders

The vertices of any graph may always be ordered in such a way that the greedy algorithm produces an optimal coloring. For, given any optimal coloring, one may order the vertices by their colors. Then when one uses a greedy algorithm with this order, the resulting coloring is automatically optimal. [7] However, because optimal graph coloring is NP-complete, any subproblem that would allow this problem to be solved quickly, including finding an optimal ordering for greedy coloring, is NP-hard. [8]

In interval graphs and chordal graphs, if the vertices are ordered in the reverse of a perfect elimination ordering, then the earlier neighbors of every vertex will form a clique. This property causes the greedy coloring to produce an optimal coloring, because it never uses more colors than are required for each of these cliques. An elimination ordering can be found in linear time, when it exists. [9]

More strongly, any perfect elimination ordering is hereditarily optimal, meaning that it is optimal both for the graph itself and for all of its induced subgraphs. The perfectly orderable graphs (which include chordal graphs, comparability graphs, and distance-hereditary graphs) are defined as graphs that have a hereditarily optimal ordering. [10] Recognizing perfectly orderable graphs is also NP-complete. [11]

Bad orders

The number of colors produced by the greedy coloring for the worst ordering of a given graph is called its Grundy number. [12] Just as finding a good vertex ordering for greedy coloring is difficult, so is finding a bad vertex ordering. It is NP-complete to determine, for a given graph G and number k, whether there exists an ordering of the vertices of G that causes the greedy algorithm to use k or more colors. In particular, this means that it is difficult to find the worst ordering for G. [12]

Graphs for which order is irrelevant

The well-colored graphs are the graphs for which all vertex orderings produce the same number of colors. This number of colors, in these graphs, equals both the chromatic number and the Grundy number. [12] They include the cographs, which are exactly the graphs in which all induced subgraphs are well-colored. [13] However, it is co-NP-complete to determine whether a graph is well-colored. [12]

If a random graph is drawn from the Erdős–Rényi model with constant probability of including each edge, then any vertex ordering that is chosen independently of the graph edges leads to a coloring whose number of colors is close to twice the optimal value, with high probability. It remains unknown whether there is any polynomial time method for finding significantly better colorings of these graphs. [3]

Degeneracy

Triangular prism.png
Square antiprism.png
The triangular prism and square antiprism, graphs whose greedy colorings using the degeneracy ordering give larger-than-optimal numbers of colors

Because optimal vertex orderings are hard to find, heuristics have been used that attempt to reduce the number of colors while not guaranteeing an optimal number of colors. A commonly used ordering for greedy coloring is to choose a vertex v of minimum degree, order the subgraph with v removed recursively, and then place v last in the ordering. The largest degree of a removed vertex that this algorithm encounters is called the degeneracy of the graph, denoted d. In the context of greedy coloring, the same ordering strategy is also called the smallest last ordering. [14] This vertex ordering, and the degeneracy, may be computed in linear time. [15] It can be viewed as an improved version of an earlier vertex ordering method, the largest-first ordering, which sorts the vertices in descending order by their degrees. [16]

With the degeneracy ordering, the greedy coloring will use at most d + 1 colors. This is because, when colored, each vertex will have at most d already-colored neighbors, so one of the first d + 1 colors will be free for it to use. [17] Greedy coloring with the degeneracy ordering can find optimal colorings for certain classes of graphs, including trees, pseudoforests, and crown graphs. [18] Markossian, Gasparian & Reed (1996) define a graph to be -perfect if, for and every induced subgraph of , the chromatic number equals the degeneracy plus one. For these graphs, the greedy algorithm with the degeneracy ordering is always optimal. [19] Every -perfect graph must be an even-hole-free graph, because even cycles have chromatic number two and degeneracy two, not matching the equality in the definition of -perfect graphs. If a graph and its complement graph are both even-hole-free, they are both -perfect. The graphs that are both perfect graphs and -perfect graphs are exactly the chordal graphs. On even-hole-free graphs more generally, the degeneracy ordering approximates the optimal coloring to within at most twice the optimal number of colors; that is, its approximation ratio is 2. [20] On unit disk graphs its approximation ratio is 3. [21] The triangular prism is the smallest graph for which one of its degeneracy orderings leads to a non-optimal coloring, and the square antiprism is the smallest graph that cannot be optimally colored using any of its degeneracy orderings. [18]

Adaptive orders

Brélaz (1979) proposes a strategy, called DSatur, for vertex ordering in greedy coloring that interleaves the construction of the ordering with the coloring process. In his version of the greedy coloring algorithm, the next vertex to color at each step is chosen as the one with the largest number of distinct colors in its neighborhood. In case of ties, a vertex of maximal degree in the subgraph of uncolored vertices is chosen from the tied vertices. By keeping track of the sets of neighboring colors and their cardinalities at each step, it is possible to implement this method in linear time. [22]

This method can find the optimal colorings for bipartite graphs, [23] all cactus graphs, all wheel graphs, all graphs on at most six vertices, and almost every -colorable graph. [24] Although Lévêque & Maffray (2005) originally claimed that this method finds optimal colorings for the Meyniel graphs, they later found a counterexample to this claim. [25]

Alternative color selection schemes

It is possible to define variations of the greedy coloring algorithm in which the vertices of the given graph are colored in a given sequence but in which the color chosen for each vertex is not necessarily the first available color. These include methods in which the uncolored part of the graph is unknown to the algorithm, or in which the algorithm is given some freedom to make better coloring choices than the basic greedy algorithm would.

Online selection

Alternative color selection strategies have been studied within the framework of online algorithms. In the online graph-coloring problem, vertices of a graph are presented one at a time in an arbitrary order to a coloring algorithm; the algorithm must choose a color for each vertex, based only on the colors of and adjacencies among already-processed vertices. In this context, one measures the quality of a color selection strategy by its competitive ratio, the ratio between the number of colors it uses and the optimal number of colors for the given graph. [26]

If no additional restrictions on the graph are given, the optimal competitive ratio is only slightly sublinear. [27] However, for interval graphs, a constant competitive ratio is possible, [28] while for bipartite graphs and sparse graphs a logarithmic ratio can be achieved. Indeed, for sparse graphs, the standard greedy coloring strategy of choosing the first available color achieves this competitive ratio, and it is possible to prove a matching lower bound on the competitive ratio of any online coloring algorithm. [26]

Parsimonous coloring

A parsimonious coloring, for a given graph and vertex ordering, has been defined to be a coloring produced by a greedy algorithm that colors the vertices in the given order, and only introduces a new color when all previous colors are adjacent to the given vertex, but can choose which color to use (instead of always choosing the smallest) when it is able to re-use an existing color. The ordered chromatic number is the smallest number of colors that can be obtained for the given ordering in this way, and the ochromatic number is the largest ordered chromatic number among all vertex colorings of a given graph. Despite its different definition, the ochromatic number always equals the Grundy number. [29]

Applications

Because it is fast and in many cases can use few colors, greedy coloring can be used in applications where a good but not optimal graph coloring is needed. One of the early applications of the greedy algorithm was to problems such as course scheduling, in which a collection of tasks must be assigned to a given set of time slots, avoiding incompatible tasks being assigned to the same time slot. [4] It can also be used in compilers for register allocation, by applying it to a graph whose vertices represent values to be assigned to registers and whose edges represent conflicts between two values that cannot be assigned to the same register. [30] In many cases, these interference graphs are chordal graphs, allowing greedy coloring to produce an optimal register assignment. [31]

In combinatorial game theory, for an impartial game given in explicit form as a directed acyclic graph whose vertices represent game positions and whose edges represent valid moves from one position to another, the greedy coloring algorithm (using the reverse of a topological ordering of the graph) calculates the nim-value of each position. These values can be used to determine optimal play in any single game or any disjunctive sum of games. [32]

For a graph of maximum degree Δ, any greedy coloring will use at most Δ + 1 colors. Brooks' theorem states that with two exceptions (cliques and odd cycles) at most Δ colors are needed. One proof of Brooks' theorem involves finding a vertex ordering in which the first two vertices are adjacent to the final vertex but not adjacent to each other, and each vertex other than the last one has at least one later neighbor. For an ordering with this property, the greedy coloring algorithm uses at most Δ colors. [33]

Notes

  1. Mitchem (1976).
  2. 1 2 Hoàng & Sritharan (2016), Theorem 28.33, p. 738; Husfeldt (2015), Algorithm G
  3. 1 2 Frieze & McDiarmid (1997).
  4. 1 2 Welsh & Powell (1967).
  5. Johnson (1974); Husfeldt (2015).
  6. Kučera (1991); Husfeldt (2015).
  7. Husfeldt (2015).
  8. Maffray (2003).
  9. Rose, Lueker & Tarjan (1976).
  10. Chvátal (1984); Husfeldt (2015).
  11. Middendorf & Pfeiffer (1990).
  12. 1 2 3 4 Zaker (2006).
  13. Christen & Selkow (1979).
  14. Mitchem (1976); Husfeldt (2015).
  15. Matula & Beck (1983).
  16. Welsh & Powell (1967); Husfeldt (2015).
  17. Matula (1968); Szekeres & Wilf (1968).
  18. 1 2 Kosowski & Manuszewski (2004).
  19. Markossian, Gasparian & Reed (1996); Maffray (2003).
  20. Markossian, Gasparian & Reed (1996).
  21. Gräf, Stumpf & Weißenfels (1998).
  22. Brélaz (1979); Lévêque & Maffray (2005).
  23. Brélaz (1979).
  24. Janczewski et al. (2001).
  25. Lévêque & Maffray (2005).
  26. 1 2 Irani (1994).
  27. Lovász, Saks & Trotter (1989); Vishwanathan (1992).
  28. Kierstead & Trotter (1981).
  29. Simmons (1982); Erdős et al. (1987).
  30. Poletto & Sarkar (1999). Although Poletto and Sarkar describe their register allocation method as not being based on graph coloring, it appears to be the same as greedy coloring.
  31. Pereira & Palsberg (2005).
  32. E.g., see Section 1.1 of Nivasch (2006).
  33. Lovász (1975).

Related Research Articles

<span class="mw-page-title-main">Bipartite graph</span> Graph divided into two independent sets

In the mathematical field of graph theory, a bipartite graph is a graph whose vertices can be divided into two disjoint and independent sets and , that is, every edge connects a vertex in to one in . Vertex sets and are usually called the parts of the graph. Equivalently, a bipartite graph is a graph that does not contain any odd-length cycles.

This is a glossary of graph theory. Graph theory is the study of graphs, systems of nodes or vertices connected in pairs by lines or edges.

<span class="mw-page-title-main">Graph coloring</span> Methodic assignment of colors to elements of a graph

In graph theory, graph coloring is a special case of graph labeling; it is an assignment of labels traditionally called "colors" to elements of a graph subject to certain constraints. In its simplest form, it is a way of coloring the vertices of a graph such that no two adjacent vertices are of the same color; this is called a vertex coloring. Similarly, an edge coloring assigns a color to each edge so that no two adjacent edges are of the same color, and a face coloring of a planar graph assigns a color to each face or region so that no two faces that share a boundary have the same color.

<span class="mw-page-title-main">Perfect graph</span> Graph with tight clique-coloring relation

In graph theory, a perfect graph is a graph in which the chromatic number equals the size of the maximum clique, both in the graph itself and in every induced subgraph. In all graphs, the chromatic number is greater than or equal to the size of the maximum clique, but they can be far apart. A graph is perfect when these numbers are equal, and remain equal after the deletion of arbitrary subsets of vertices.

<span class="mw-page-title-main">Perfect graph theorem</span> An undirected graph is perfect if and only if its complement graph is also perfect

In graph theory, the perfect graph theorem of László Lovász states that an undirected graph is perfect if and only if its complement graph is also perfect. This result had been conjectured by Berge, and it is sometimes called the weak perfect graph theorem to distinguish it from the strong perfect graph theorem characterizing perfect graphs by their forbidden induced subgraphs.

<span class="mw-page-title-main">Edge coloring</span> Problem of coloring a graphs edges such that meeting edges do not match

In graph theory, a proper edge coloring of a graph is an assignment of "colors" to the edges of the graph so that no two incident edges have the same color. For example, the figure to the right shows an edge coloring of a graph by the colors red, blue, and green. Edge colorings are one of several different types of graph coloring. The edge-coloring problem asks whether it is possible to color the edges of a given graph using at most k different colors, for a given value of k, or with the fewest possible colors. The minimum required number of colors for the edges of a given graph is called the chromatic index of the graph. For example, the edges of the graph in the illustration can be colored by three colors but cannot be colored by two colors, so the graph shown has chromatic index three.

In graph theory, a branch of mathematics, list coloring is a type of graph coloring where each vertex can be restricted to a list of allowed colors. It was first studied in the 1970s in independent papers by Vizing and by Erdős, Rubin, and Taylor.

<span class="mw-page-title-main">Chordal graph</span> Graph where all long cycles have a chord

In the mathematical area of graph theory, a chordal graph is one in which all cycles of four or more vertices have a chord, which is an edge that is not part of the cycle but connects two vertices of the cycle. Equivalently, every induced cycle in the graph should have exactly three vertices. The chordal graphs may also be characterized as the graphs that have perfect elimination orderings, as the graphs in which each minimal separator is a clique, and as the intersection graphs of subtrees of a tree. They are sometimes also called rigid circuit graphs or triangulated graphs.

<span class="mw-page-title-main">Grundy number</span> Maximum number of colors obtainable by a greedy graph coloring algorithm

In graph theory, the Grundy number or Grundy chromatic number of an undirected graph is the maximum number of colors that can be used by a greedy coloring strategy that considers the vertices of the graph in sequence and assigns each vertex its first available color, using a vertex ordering chosen to use as many colors as possible. Grundy numbers are named after P. M. Grundy, who studied an analogous concept for directed graphs in 1939. The undirected version was introduced by Christen & Selkow (1979).

<span class="mw-page-title-main">Kőnig's theorem (graph theory)</span> Theorem showing that maximum matching and minimum vertex cover are equivalent for bipartite graphs

In the mathematical area of graph theory, Kőnig's theorem, proved by Dénes Kőnig (1931), describes an equivalence between the maximum matching problem and the minimum vertex cover problem in bipartite graphs. It was discovered independently, also in 1931, by Jenő Egerváry in the more general case of weighted graphs.

<span class="mw-page-title-main">Brooks' theorem</span>

In graph theory, Brooks' theorem states a relationship between the maximum degree of a graph and its chromatic number. According to the theorem, in a connected graph in which every vertex has at most Δ neighbors, the vertices can be colored with only Δ colors, except for two cases, complete graphs and cycle graphs of odd length, which require Δ + 1 colors.

In graph theory, a perfectly orderable graph is a graph whose vertices can be ordered in such a way that a greedy coloring algorithm with that ordering optimally colors every induced subgraph of the given graph. Perfectly orderable graphs form a special case of the perfect graphs, and they include the chordal graphs, comparability graphs, and distance-hereditary graphs. However, testing whether a graph is perfectly orderable is NP-complete.

In graph theory, a branch of mathematics, a crown graph on 2n vertices is an undirected graph with two sets of vertices {u1, u2, …, un} and {v1, v2, …, vn} and with an edge from ui to vj whenever ij.

In graph theory, an area of mathematics, an equitable coloring is an assignment of colors to the vertices of an undirected graph, in such a way that

In computer science, lexicographic breadth-first search or Lex-BFS is a linear time algorithm for ordering the vertices of a graph. The algorithm is different from a breadth-first search, but it produces an ordering that is consistent with breadth-first search.

<span class="mw-page-title-main">Degeneracy (graph theory)</span> Measurement of graph sparsity

In graph theory, a k-degenerate graph is an undirected graph in which every subgraph has a vertex of degree at most k: that is, some vertex in the subgraph touches k or fewer of the subgraph's edges. The degeneracy of a graph is the smallest value of k for which it is k-degenerate. The degeneracy of a graph is a measure of how sparse it is, and is within a constant factor of other sparsity measures such as the arboricity of a graph.

<span class="mw-page-title-main">Graph power</span> Graph operation: linking all pairs of nodes of distance ≤ k

In graph theory, a branch of mathematics, the kth powerGk of an undirected graph G is another graph that has the same set of vertices, but in which two vertices are adjacent when their distance in G is at most k. Powers of graphs are referred to using terminology similar to that of exponentiation of numbers: G2 is called the square of G, G3 is called the cube of G, etc.

<span class="mw-page-title-main">Well-colored graph</span>

In graph theory, a subfield of mathematics, a well-colored graph is an undirected graph for which greedy coloring uses the same number of colors regardless of the order in which colors are chosen for its vertices. That is, for these graphs, the chromatic number and Grundy number are equal.

<span class="mw-page-title-main">Cereceda's conjecture</span> Unsolved problem in the mathematics of graph coloring

In the mathematics of graph coloring, Cereceda’s conjecture is an unsolved problem on the distance between pairs of colorings of sparse graphs. It states that, for two different colorings of a graph of degeneracy d, both using at most d + 2 colors, it should be possible to reconfigure one coloring into the other by changing the color of one vertex at a time, using a number of steps that is quadratic in the size of the graph. The conjecture is named after Luis Cereceda, who formulated it in his 2007 doctoral dissertation.

The Earth–Moon problem is an unsolved problem on graph coloring in mathematics. It is an extension of the planar map coloring problem, and was posed by Gerhard Ringel in 1959. In mathematical terms, it seeks the chromatic number of biplanar graphs. It is known that this number is at least 9 and at most 12.

References