An optimal complexity algorithm for minimum-time velocity planning