Viterbi decoder K=3 using ADD-COMPARE-SELECT Operation
For each state in the Viterbi decoder, you want to keep track of the shortest path through the trellis that ends in that state. The trellis structure defines what all of the possible state transitions are.
Therefore, each time you get a new symbol observation, you loop through each state in your decoder and you:

Add the metric for each transition that ends in the state to the metric of the previous state, yielding a total metric for each state-&gt;state transition,
Compare the list of total metrics, and
Select the minimum metric as the most likely path to the current state.

The Viterbi algorithm, in this way, is really just repeated execution of this add-compare-select process, thus keeping track of the minimum-cost path to each state at any given time.