# LZ77与LZ78

**LZ77与LZ78**是[雅各布·齐夫](https://www.edgepedia.org/zh/jacob-ziv)（Jacob Ziv）和[亚伯拉罕·伦佩尔](https://www.edgepedia.org/zh/abraham-lempel)（Abraham Lempel）分别于1977年和1978年发表在《IEEE信息论汇刊》（IEEE Transactions on Information Theory）上的两种无损数据压缩算法。两者都是通用字典方法：它们通过用对先前出现内容的引用替代重复数据来压缩任意输入，而不假定信源的概率模型。LZ77作用于近期文本的滑动窗口，而LZ78在读取时构建显式的短语字典。它们是当今大多数实用压缩器的祖先，包括LZ77一侧的DEFLATE（gzip、ZIP、PNG）、LZMA、LZ4、Zstandard和Brotli，以及LZ78一侧的LZW（GIF、TIFF）。<sup>[1](https://ieeexplore.ieee.org/abstract/document/1055714/authors)</sup><sup> • </sup><sup>[2](https://explore.openaire.eu/search/publication?pid=10.1109%2Ftit.1978.1055934)</sup><sup> • </sup><sup>[3](https://ethw.org/History_of_Lossless_Data_Compression_Algorithms)</sup>

| 关键事实 | 详情 |
|---|---|
| 原始论文 | 《一种用于顺序数据压缩的通用算法》（"A universal algorithm for sequential data compression"，1977，IEEE Trans. Inf. Theory 23(3)）与《通过可变速率编码压缩单个序列》（"Compression of individual sequences via variable-rate coding"，1978，IEEE Trans. Inf. Theory 24(5)，第530–536页），均由雅各布·齐夫和亚伯拉罕·伦佩尔发表<sup>[1](https://ieeexplore.ieee.org/abstract/document/1055714/authors)</sup><sup> • </sup><sup>[2](https://explore.openaire.eu/search/publication?pid=10.1109%2Ftit.1978.1055934)</sup> |
| LZ77机制 | 用一个指针替代冗余片段，指针给出指向滑动窗口的后向偏移和匹配长度；找不到匹配时，输出空指针加一个字面字节<sup>[4](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-wusp/fb98aa28-5cd7-407f-8869-a6cef1ff1ccb)</sup> |
| LZ78机制 | 在单遍处理中动态构建短语字典；每次输出一个字典索引，加上偏离匹配短语的第一个符号<sup>[5](https://research.ijcaonline.org/volume56/number3/pxc3882850.pdf)</sup> |
| 理论性质 | 随着输入长度增长，这两种算法以及LZW都渐近达到单个序列的有限状态可压缩性；LZ78对平稳遍历信源是渐近最优的<sup>[6](https://arxiv.org/abs/1409.1323)</sup><sup> • </sup><sup>[5](https://research.ijcaonline.org/volume56/number3/pxc3882850.pdf)</sup> |
| 主要派生算法 | LZ77线：LZSS、DEFLATE、LZMA、LZ4、Zstandard、Brotli；LZ78线：LZW（韦尔奇，1984）、LZC、LZMW<sup>[7](https://patents.google.com/patent/US7868788B2/en)</sup><sup> • </sup><sup>[3](https://ethw.org/History_of_Lossless_Data_Compression_Algorithms)</sup> |
| 实用格式 | DEFLATE使用32 KB窗口，匹配长度可达258字节；LZ4使用64 KB窗口，不带熵编码器<sup>[8](https://www.rfc-editor.org/rfc/rfc1951.pdf)</sup><sup> • </sup><sup>[9](https://github.com/lz4/lz4/blob/dev/doc/lz4_Block_format.md)</sup> |

## LZ77：使用滑动窗口的压缩

LZ77压缩时，对当前编码位置的数据，在已处理字节的窗口内寻找最长匹配。窗口开始时为空，增长到固定大小W，然后随编码位置滑动。匹配以一个包含后向偏移和长度的指针形式输出；由于甚至连一字节的匹配也可能不存在，编码器还会输出匹配之后的第一个字面字节，而当完全不存在匹配时，它输出一个空指针（偏移0，长度0）外加编码位置处的字节。<sup>[4](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-wusp/fb98aa28-5cd7-407f-8869-a6cef1ff1ccb)</sup>

指针的长度可以超过其偏移。这编码了重叠重复：复制操作在到达编码位置后返回起始偏移，因此像重复的两字节模式这样的连续串可以用单个指针描述。<sup>[4](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-wusp/fb98aa28-5cd7-407f-8869-a6cef1ff1ccb)</sup>

**解码比编码简单。** 解码器不搜索匹配；它跟随每个指针并复制所指示的字节，因此LZ77解码通常比编码快得多，编码时必须找到历史窗口中最长匹配子串。<sup>[10](https://gyires.inf.unideb.hu/KMITT/a51/ch03s03.html)</sup>

## LZ78：使用增长字典的压缩

LZ78采取不同的方法。它不按距离对原始文本寻址，而是由编码器和解码器各自维护一份相同的短语字典，该字典在单遍处理中动态构建。编码器找出剩余输入中已在字典内的最长前缀，输出该短语的索引以及打破匹配的下一个符号，并把扩展后的短语加入字典。不传输地址与长度的组合，只传输字典索引和偏离符号。<sup>[5](https://research.ijcaonline.org/volume56/number3/pxc3882850.pdf)</sup><sup> • </sup><sup>[11](https://www.philippe-fournier-viger.com/spmf/lz78.pdf)</sup>

以色列理工学院（Technion）荣休教授雅各布·齐夫把这一机制描述为构建一棵短语树：在看到第一个比特后，字典持有两个编码；此后每来一个比特，就发送一个指向某一分支的指针，同时沿该分支扩展字典，于是出现更频繁的序列会长出更长的分支。<sup>[12](https://spectrum.ieee.org/from-winzips-to-cat-gifs-jacob-zivs-algorithms-have-powered-decades-of-compression)</sup>

**渐近最优性。** 当输入由平稳遍历信源产生时，随着输入规模增长，LZ78压缩是渐近最优的：它以信源熵所决定的最小尺寸编码任意长的字符串。实践中收敛相对缓慢，性能与LZ77相当；LZ方法的实际吸引力来自高效实现，而不是渐近极限。<sup>[5](https://research.ijcaonline.org/volume56/number3/pxc3882850.pdf)</sup> 更一般地，无限制的LZ78算法与LZ77、LZW一起，渐近达到有限状态可压缩性，即任何信息无损有限状态编码器在无限长单个序列上所能达到的最佳比率。<sup>[6](https://arxiv.org/abs/1409.1323)</sup>

## 两者的差异

两族算法的输出差异有多大，它们的数据结构差异就有多大：LZ77基于原始文本缓冲区工作，通过距离进行引用；而LZ78通过索引引用短语字典。<sup>[13](https://distillcourse.com/courses/information-theory/lessons/dictionary-coding)</sup> LZ77可访问前一窗口中的所有符号串，而LZ78一次一个字符地构建字典，从而逐步分离出频繁使用的字符串。<sup>[5](https://research.ijcaonline.org/volume56/number3/pxc3882850.pdf)</sup>

差异体现在具体应用中。LZ78压缩高度重复数据集的效果不如LZ77，但文本的LZ78编码可以被增强，以支持O(log log n + l)时间的随机访问读取，这使它可用于压缩索引。<sup>[14](https://pmc.ncbi.nlm.nih.gov/articles/PMC4321636/)</sup> 在最坏情况分析中，LZ78和其他流行的基于引用的方法在短语数量上明显差于LZ77。<sup>[15](https://www.sciencedirect.com/science/article/abs/pii/S0020019018301832)</sup>

## 派生算法与采用

两种算法都催生了许多变体。在LZ77一方，LZSS（斯托勒（Storer）和希曼斯基（Szymanski））去除了大多数字面量开销；RFC 1951定义的DEFLATE把LZ77与[霍夫曼编码](https://www.edgepedia.org/zh/huffman-coding)（Huffman coding）结合起来：它使用32 KB窗口，将匹配长度限制为258字节，并分别用一棵霍夫曼树编码字面量和长度、用另一棵编码距离。DEFLATE是ZIP、gzip和PNG的基础。<sup>[8](https://www.rfc-editor.org/rfc/rfc1951.pdf)</sup><sup> • </sup><sup>[3](https://ethw.org/History_of_Lossless_Data_Compression_Algorithms)</sup> 后来的LZ77后裔包括LZMA、LZ4、Zstandard和Brotli。LZ4是一种LZ77型压缩器，具有固定的面向字节格式、64 KB窗口，且没有熵编码后端，设计目标是速度。<sup>[9](https://github.com/lz4/lz4/blob/dev/doc/lz4_Block_format.md)</sup> Zstandard把大窗口与FSE和霍夫曼熵编码配对，Brotli则把LZ77后向引用与霍夫曼编码以及一个内置静态字典结合起来，该字典有助于处理短的HTTP响应。<sup>[16](https://developer.apple.com/documentation/compression/compression_brotli?changes=la)</sup>

在LZ78一方，最著名的修改是[特里·韦尔奇](https://www.edgepedia.org/zh/terry-welch)（Terry Welch）于1984年设计的LZW；它被UNIX compress工具（作为变体LZC）、GIF标准、V.42bis调制解调器标准采用，并成为TIFF和PDF中的一个选项。<sup>[7](https://patents.google.com/patent/US7868788B2/en)</sup>

**专利塑造了哪个族系占据主导。** 1984年斯佩里（Sperry）为LZW取得专利，并追究GIF的软件供应商、服务器管理员和最终用户之后，LZ78谱系的算法便背负了专利负担。UNIX社群从基于LZC的compress转向基于DEFLATE的gzip，并转向bzip2；这两者在多数情况下比LZW达到更高的压缩率。LZW专利于2003年到期，但那时LZW已在很大程度上被取代，主要存活于GIF压缩中，而当今大多数广泛使用的算法源自LZ77。<sup>[3](https://ethw.org/History_of_Lossless_Data_Compression_Algorithms)</sup>

## 后续发展

对原始格式的研究仍在继续。一项2026年对LZ77编码器的分析表明，1977年原始的固定字段标记格式在均匀信源上留下Ω(log B/B)量级的冗余，其中B = log₂ W是以比特计的窗口大小；而依赖匹配长度的滑动窗口——为短匹配提供更小的窗口和更短的距离字段——可以把这一冗余降至O(log log B/B)，同时保留算法的通用性保证。<sup>[17](https://arxiv.org/abs/2610.06530)</sup> LZ77短语分解的研究也仍然活跃，因为决定基于LZ的压缩索引大小的是短语数量，而不是编码后的大小；而高效计算一个小规模分解是索引构建中的瓶颈。<sup>[18](https://arxiv.org/abs/2609.30193)</sup>

## References

1. [J. Ziv and A. Lempel (1977). A universal algorithm for sequential data compression. IEEE Transactions on Information Theory 23(3).](https://ieeexplore.ieee.org/abstract/document/1055714/authors)
2. [J. Ziv and A. Lempel (1978). Compression of individual sequences via variable-rate coding. IEEE Transactions on Information Theory 24(5), 530–536.](https://explore.openaire.eu/search/publication?pid=10.1109%2Ftit.1978.1055934)
3. [History of Lossless Data Compression Algorithms, Engineering and Technology History Wiki](https://ethw.org/History_of_Lossless_Data_Compression_Algorithms)
4. [MS-WUSP: LZ77 Compression Algorithm, Microsoft Learn](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-wusp/fb98aa28-5cd7-407f-8869-a6cef1ff1ccb)
5. [Comparative Analysis of Lossless Text Compression Techniques, International Journal of Computer Applications 56(3), 2012](https://research.ijcaonline.org/volume56/number3/pxc3882850.pdf)
6. [J. Ziv (2014). A Constrained-Dictionary version of LZ78 asymptotically achieves the Finite-State Compressibility. arXiv.](https://arxiv.org/abs/1409.1323)
7. [US7868788B2: System and method for encoding data based on a compression technique with security features, Google Patents](https://patents.google.com/patent/US7868788B2/en)
8. [P. Deutsch (1996). DEFLATE Compressed Data Format Specification, RFC 1951](https://www.rfc-editor.org/rfc/rfc1951.pdf)
9. [LZ4 Block Format Description, lz4 GitHub documentation](https://github.com/lz4/lz4/blob/dev/doc/lz4_Block_format.md)
10. [Ziv-Lempel coding, University of Debrecen course notes](https://gyires.inf.unideb.hu/KMITT/a51/ch03s03.html)
11. [LZ78 algorithm description, SPMF documentation](https://www.philippe-fournier-viger.com/spmf/lz78.pdf)
12. [From WinZips to Cat GIFs, Jacob Ziv's Algorithms Have Powered Decades of Compression, IEEE Spectrum](https://spectrum.ieee.org/from-winzips-to-cat-gifs-jacob-zivs-algorithms-have-powered-decades-of-compression)
13. [Dictionary coding and universal compression, distillcourse](https://distillcourse.com/courses/information-theory/lessons/dictionary-coding)
14. [Searching and Indexing Genomic Databases via Kernelization, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC4321636/)
15. [Comparison of LZ77-type parsings, Information Processing Letters / ScienceDirect](https://www.sciencedirect.com/science/article/abs/pii/S0020019018301832)
16. [COMPRESSION_BROTLI, Apple Developer Documentation](https://developer.apple.com/documentation/compression/compression_brotli?changes=la)
17. [Y. Wu (2026). Improved LZ77 Compression with Match-Length-Dependent Sliding Windows. arXiv.](https://arxiv.org/abs/2610.06530)
18. [J. Ellert, L. Nalbach (2026). Practical and Space-Efficient LZ77 and LZ Pre-Compression via String Synchronizing Sets. arXiv.](https://arxiv.org/abs/2609.30193)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Algorithms and computational methods › Numerical, string, and geometric algorithms › String algorithms

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/lz77-and-lz78

English original: https://www.edgepedia.org/lz77-and-lz78
