Abstract
The optimal prefixfree code problem is to determine, for a given array p=[p i ¦i∈{1...n}] of n weights, an integer array l= [l i ¦∈{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 l i overwriting p i , 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.
Preview
Unable to display preview. Download preview PDF.
References
J.L. Bentley and M.D. McIlroy. Engineering a sorting function. Software—Practice and Experience 23 (1993) 1249–1265.
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.
D. Hirschberg and D. Lelewer. Efficient decoding of prefix codes. Communications of the ACM 33 (1990) 449–459.
D.A. Huffman. A method for the construction of minimum-redundancy codes. Proceedings of the Inst. Radio Engineers 40 (1952) 1098–1101.
L.L. Larmore and T.M. Przytycka. Constructing Huffman trees in parallel. SIAM Journal on Computing. To appear.
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.
D.A. Lelewer and D.S. Hirschberg. Data compression. Computing Surveys 19 (1987) 261–296.
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.
R. Sedgewick. Algorithms in C. 2nd Edition, Addison-Wesley, Reading, Massachusetts (1990).
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).
Author information
Authors and Affiliations
Editor information
Rights and permissions
Copyright information
© 1995 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Moffat, A., Katajainen, J. (1995). In-place calculation of minimum-redundancy codes. In: Akl, S.G., Dehne, F., Sack, JR., Santoro, N. (eds) Algorithms and Data Structures. WADS 1995. Lecture Notes in Computer Science, vol 955. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-60220-8_79
Download citation
DOI: https://doi.org/10.1007/3-540-60220-8_79
Published:
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-60220-0
Online ISBN: 978-3-540-44747-4
eBook Packages: Springer Book Archive