Implementing viterbi search algorithm using tree.