Greedy algorithm (source code)

= Greedy algorithm
{wiki}

A <greedy algorithm> commits to a locally preferred next choice without revisiting earlier choices. Its rule needs a justification to guarantee a globally optimal result: the largest-individual-value rule in the <0-1 knapsack problem> example fails, whereas <Dijkstra's algorithm> correctly settles the smallest tentative distance under its nonnegative-edge assumptions.