In: Computer Science
Give a greedy algorithm to make a reasonable attempt at coloring a graph in ?(? + ?) time. In pseudo code
We can use greedy algorithm to color a graph. Since this is a Non polynomial complete task, we can't have the choice of using minimum colors, but we can surely set an upper limit using greedy algorithm.
So, the algorithm is-
Fill color in 1st vertice with the 1st colour we have.
And now for the rest of the vertices do this-
Choose the current vertice, fill it with color that has the least value numerically and hasn't been used before on any vertices that are located adjacently to it. Use a different color and mark it as used.
Below is the code for the given algorithm/pseudocode. Time complexity- O(V+E).
OUTPUT-