best case scenario algorithm