implemented Viterbi algorithm