Grokking pseudo-code for solution to gas station problem
The second implementation is correct (so Theorem 2.2 survives): If the condition $c(v) &gt; c(u)$ causes the inner while to halt, that same value of $v$ will be give the optimal value for every following value of $g$, simply because the condition is independent of $g$.