entire algorithm with bigrams