Springer Nature is making Coronavirus research free. View research | View latest news | Sign up for updates

A Fast Algorithm for Adaptive Prefix Coding

  • 112 Accesses

  • 5 Citations


In this paper we present a new algorithm for adaptive prefix coding. Our algorithm encodes a text S of m symbols in O(m) time, i.e., in O(1) amortized time per symbol. The length of the encoded string is bounded above by (H+1)m+O(nlog 2 m) bits where n is the alphabet size and H is the entropy.

This is the first algorithm that adaptively encodes a text in O(m) time and achieves an almost optimal bound on the encoding length in the worst case. Besides that, our algorithm does not depend on an explicit code tree traversal.

This is a preview of subscription content, log in to check access.


  1. 1.

    Andersson, A., Miltersen, P.B., Thorup, M.: Fusion trees can be implemented with AC0 instructions only. Theor. Comput. Sci. 215, 337–344 (1999)

  2. 2.

    Connell, J.B.: A Huffman-Shannon-Fano code. Proc. IEEE 61, 1046–1047 (1973)

  3. 3.

    Capocelli, R.M., De Santis, A.: New bounds on the redundancy of Huffman codes. IEEE Trans. Inf. Theory 37, 1095–1104 (1991)

  4. 4.

    Faller, N.: An adaptive system for data compression. In: Proc. 7th Asilomar Conference on Circuits, Systems, and Computers, pp. 593–597 (1973)

  5. 5.

    Fredman, M.L., Willard, D.E.: Surpassing the information theoretic bound with fusion trees. J. Comput. Syst. Sci. 47, 424–436 (1993)

  6. 6.

    Gagie, T.: Dynamic Shannon coding. In: Proc. the 12th European Symposium on Algorithms. LNCS, vol. 3221, pp. 359–370. Springer, Berlin (2004), see also Inf. Process. Lett. 102, 113–117 (2007)

  7. 7.

    Gallager, R.G.: Variations on a theme by Huffman. IEEE Trans. Inf. Theory 24, 668–674 (1978)

  8. 8.

    Golumbic, M.C.: Combinatorial merging. IEEE Trans. Comput. 25, 1164–1167 (1976)

  9. 9.

    Huffman, D.A.: A method for construction of minimum-redundancy codes. Proc. IRE 40, 1098–1101 (1952)

  10. 10.

    Klein, S.T.: Skeleton trees for the efficient decoding of Huffman encoded texts. Inf. Retr. 3, 7–23 (2000). A preliminary version, Space- and time-efficient decoding with canonical Huffman trees, appeared in Proc. the 8th Annual Symposium on Combinatorial Pattern Matching. LNCS, vol. 1264, pp. 65–75 (1997).

  11. 11.

    Knuth, D.E.: Dynamic Huffman coding. J. Algorithms 6, 163–180 (1985)

  12. 12.

    Lelewer, D.A., Hirschberg, D.S.: Data compression. ACM Comput. Surv. 19, 261–296 (1987)

  13. 13.

    Milidiú, R.L., Laber, E.S., Pessoa, A.A.: Bounding the compression loss of the FGK algorithm. J. Algorithms 32, 195–211 (1999)

  14. 14.

    Moffat, A., Turpin, A.: On the implementation of minimum-redundancy prefix codes. IEEE Trans. Commun. 45, 1200–1207 (1997)

  15. 15.

    Rueda, L., Oommen, B.J.: A fast and efficient nearly-optimal adaptive Fano coding scheme. Inf. Sci. 176, 1656–1683 (2006)

  16. 16.

    Shannon, C.E.: A mathematical theory of communication. Bell Syst. Techn. J. 27, 379–423 (1948)

  17. 17.

    Shannon, C.E.: A mathematical theory of communication. Bell Syst. Techn. J. 27, 623–656 (1948)

  18. 18.

    Schwartz, E.S., Kallick, B.: Generating a canonical prefix encoding. Commun. ACM 7, 166–169 (1964)

  19. 19.

    Turpin, A., Moffat, A.: On-line adaptive canonical prefix coding with bounded compression loss. IEEE Trans. Inf. Theory 47, 88–98 (2001)

  20. 20.

    Vitter, J.S.: Design and analysis of dynamic Huffman codes. J. ACM 34, 825–845 (1987)

Download references

Author information

Correspondence to Yakov Nekrich.

Additional information

A preliminary version of this paper appeared in the Proceedings of the 2006 IEEE International Symposium on Information Theory (ISIT 2006).

M. Karpinski’s work partially supported by a DFG grant, Max-Planck Research Prize, and IST grant 14036 (RAND-APX).

Y. Nekrich’s work partially supported by IST grant 14036 (RAND-APX).

Rights and permissions

Reprints and Permissions

About this article

Cite this article

Karpinski, M., Nekrich, Y. A Fast Algorithm for Adaptive Prefix Coding. Algorithmica 55, 29–41 (2009).

Download citation


  • Data compression
  • Prefix-free codes
  • Adaptive coding