 Suppose we want to color an arbitrary graph. One potential problem is that when we assign a color to a vertex, this limits the possibilities for the adjacent vertices, which limits the possibilities for the vertices at distance 2, which limits the possibilities for the vertices at distance 3, and in fact, every vertex in the graph. This means we can't reliably assign colors to vertices that are far apart. So to avoid this, we can begin at any vertex and assign it a color, then assign its neighbors a color, Lather, Rins, Repeat, until we color the graph. So let's describe this as an algorithm. We'll assume our colors are 1, 2, 3, and so on, up to some maximum value of k, which at this point we won't predetermine. We can select a vertex v1, assign it the lowest numbered color different from its neighbors, go to an adjacent vertex, then Lather, Rins, Repeat. For example, we might try to find a coloring of this graph. We'll choose the starting vertex, about this one, and give it a color, about 1. We'll then choose one of the adjacent vertices, about this one. Since this is adjacent to a vertex colored 1, we have to give it a different color number, so we'll give it color 2. Now we'll go to an adjacent vertex. Say this one. Since this is adjacent to a vertex colored 2, we can give it color 1. That's the lowest color number that does not appear in any of the adjacent vertices. We go to an adjacent vertex, and from here there's only one adjacent vertex. Since this vertex's neighbors have colors 1 and 2, we assign it color 3, and finally we go to the last vertex, and we note that at this point, its neighbors have colors 1, 2, and 3, so we assign it color 4, and so our graph is 4 colorable. While this is a way to color the graph, is it an algorithm? Remember, an algorithm must terminate and always produce an answer. Since we eventually go through all the vertices, this algorithm definitely terminates. We'll assume the graph is connected since if it isn't, we can apply the algorithm to the connected parts. And since we always assign a color to a vertex distinct from the colors of its neighbors, we'll always get a K coloring. So this is in fact an algorithm. However, while this is an algorithm, is it a good algorithm? And in particular, we have a bunch of choices we make here, and so we might ask, do we get different answers if we make different choices? Well, let's see. So again, we'll assign the first vertex color 1. This time, let's go up to this neighbor. If we go to another neighbor, we'd assign it color 2. Then another neighbor, we'd assign this color 1. Then the next neighbor gets color 2. Our last vertex, we're adjacent to vertices with colors 1 and 2, so we can assign this color 3, and our graph is 3-colorable. So notice that when we went around the vertices this way, we were able to color the graph using only 3 colors. Again, just because a graph is 3-colorable doesn't mean that its chromatic number is 3. It just means we haven't found one that's less. So we might ask, is the graph 2-colorable? And in this case, note that it does contain some 3 cycles, so it can't be bipartite, which means it can't be 2-colorable. Now, you might notice that our first graph coloring algorithm is actually depth-first. We follow a path down through the vertices that are connected. What if we tried a breadth-first algorithm? Try it! So we'll start at the vertex, and stop me if you've heard this before. We'll assign it color 1. The adjacent vertices are actually connected, so we have to introduce two new colors. So we'll label them 2 and 3. The next vertex is not connected to the first, so we can reuse that color, and the last vertex can be assigned one of the already used colors, so this graph is 3-colorable. Well, let's do a more complicated graph. Let's do this both ways. We'll use our depth-first coloring and then our breadth-first coloring, and then see if we can find the chromatic number of the graph. So for the depth-first coloring, we'll start at a vertex about this one. We'll assign it the first color, and we'll go to an adjacent vertex and color it. And we'll lather, rinse, repeat until we've colored every vertex in the graph. And so we can find a 3-coloring of the graph. If we do a breadth-first search, we'll start at a vertex, and we'll expand to include all the adjacent vertices, and since some of these adjacent vertices are connected, that means we'll have to assign our colors a little bit more carefully, and then we'll expand from those vertices, which gives us another 3-coloring. And since a 3-coloring exists, the chromatic number is less than or equal to 3, and since there are odd cycles, G is not bipartite, so the chromatic number can't be 2, and since G is not totally disjoint, the chromatic number can't be 1, and so our only choice is 3.