the base coloring algorithm