Linear time algorithms for convex and monotone approximation