Coloring algorithms for sparse Jacobian and Hessian matrices