a randomized algorithm for graph 3-coloring
today i came across this chinese blog about randomized algorithms and thought it lacked a little more details. moreover, i haven’t found any blogs about this algorithm and i thought the idea behind it was really interesting and could provide some inspiration for problem setters.
the problem is simple: finding a 3-coloring of a graph. we all know it’s NP hard but this is when randomization comes in handy.
let’s fix the color of one vertex to avoid finding symmetrical colorings, and for each vertex let’s set a forbidden color in the set at random.
can we color our graph using the colors we’re allowed to use? we can check this modeling the constraints as an instance of 2SAT.
2SAT?
for each vertex , let be its set of allowed colors . we define as the boolean variable that equals if and if .
now, we add the color restrictions on edges depending on the color sets. for example, if and , we will add the following constraint.
why does this work? if the clause is obviously true and this makes sense since isnt allowed in , so any color choice from the other vertex would be ok.
on the other hand, if , has to equal , otherwise we’d have two edges with the same color.
bounds on probabilities
this algorithm has a success probability lower bound of . this can be proven by taking an arbitrary valid 3-coloring and seeing that for each node we’re not discarding the right color with probability .
this means, if we want to find a solution with a probability of , we can repeat our algorithm
times.
is this good?
the expected number of trials to get a correct answer is , so the average runtime is which is, sadly, exponential.
for , we’d need around iterations, and for higher numbers the algorithm would run forever.
so, is this good? no!!! but the idea behind it is pretty neat, which is why i posted this :>
maybe if the graph is random and sparse enough or its known to have multiple 3-colorings, the expected number of trials could be way smaller and this algorithm could be actually good. maybe if we combine it with pruning? i don’t know, though if i end up finding a way to optimize it im gonna post it here. (spoiler: i wont)