In-place calculation of minimum-redundancy codes

  • Alistair Moffat
  • Jyrki Katajainen
Invited Presentation
Part of the Lecture Notes in Computer Science book series (LNCS, volume 955)

Abstract

The optimal prefixfree code problem is to determine, for a given array p=[pi¦i∈{1...n}] of n weights, an integer array l= [li¦∈{1...n}] of n codeword lengths such that \(\sum\nolimits_{i = 1}^n {2^{ - l_i } \leqslant 1}\)and \(\sum\nolimits_{i = 1}^n {p_i l_i }\)is minmized. Huffman's famous greedy algorithm solves this problem in O(n log n) time, if p is unsorted; and can be implemented to execute in O(n) time, if the input array p is sorted. Here we consider the space requirements of the greedy method. We show that if p is sorted then it is possible to calculate the array l in-place, with li overwriting pi, in O(n) time and using O(1) additional space. The new implementation leads directly to an O(n log n)-time and n + O(1) words of extra space implementation for the case when p is not sorted. The proposed method is simple to implement and executes quickly.

Keywords

Prefix-free code Huffman code in-place algorithm data compression 

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    J.L. Bentley and M.D. McIlroy. Engineering a sorting function. Software—Practice and Experience 23 (1993) 1249–1265.Google Scholar
  2. 2.
    S. Carlsson, J. Katajainen, and J. Teuhola. In-place linear probing sort. Submitted. Preliminary version appeared in Proceedings of the 9th Symposium on Theoretical Aspects of Computer Science, Lecture Notes in Computer Science 577, Springer-Verlag, Berlin/Heidelberg, Germany (1992) 581–587.Google Scholar
  3. 3.
    D. Hirschberg and D. Lelewer. Efficient decoding of prefix codes. Communications of the ACM 33 (1990) 449–459.CrossRefGoogle Scholar
  4. 4.
    D.A. Huffman. A method for the construction of minimum-redundancy codes. Proceedings of the Inst. Radio Engineers 40 (1952) 1098–1101.Google Scholar
  5. 5.
    L.L. Larmore and T.M. Przytycka. Constructing Huffman trees in parallel. SIAM Journal on Computing. To appear.Google Scholar
  6. 6.
    J. van Leeuwen. On the construction of Huffman trees. In Proceedings of the 3rd International Colloquium on Automata, Languages and Programming, Edinburgh University Press, Edinburgh, Scotland (1976) 382–410.Google Scholar
  7. 7.
    D.A. Lelewer and D.S. Hirschberg. Data compression. Computing Surveys 19 (1987) 261–296.CrossRefGoogle Scholar
  8. 8.
    A. Moffat, A. Turpin, and J. Katajainen. Space-efficient construction of optimal prefix codes. Proceedings of the 5th IEEE Data Compression Conference, IEEE Computer Society Press, Los Alamitos, California (1995) 192–201.Google Scholar
  9. 9.
    R. Sedgewick. Algorithms in C. 2nd Edition, Addison-Wesley, Reading, Massachusetts (1990).Google Scholar
  10. 10.
    I.H. Witten, A. Moffat, and T.C. Bell. Managing Gigabytes: Compressing and Indexing Documents and Images. Van Nostrand Reinhold, New York, New York (1994).Google Scholar

Copyright information

© Springer-Verlag 1995

Authors and Affiliations

  • Alistair Moffat
    • 1
  • Jyrki Katajainen
    • 2
  1. 1.Department of Computer ScienceThe University of MelbourneParkvilleAustralia
  2. 2.Department of Computer ScienceUniversity of CopenhagenCopenhagen EastDenmark

Personalised recommendations