  We resolve the fundamental problem of online decoding with general $n^{th}$
order ergodic Markov chain models. Specifically, we provide deterministic and
randomized algorithms whose performance is close to that of the optimal offline
algorithm even when latency is small. Our algorithms admit efficient
implementation via dynamic programs, and readily extend to (adversarial)
non-stationary or time-varying settings. We also establish lower bounds for
online methods under latency constraints in both deterministic and randomized
settings, and show that no online algorithm can perform significantly better
than our algorithms. Empirically, just with latency one, our algorithm
outperforms the online step algorithm by over 30\% in terms of decoding
agreement with the optimal algorithm on genome sequence data.
