Viterbi Algorithm implementation