Skip to content

Lempel–Ziv–Welch

An adaptive lossless dictionary coder whose encoder and decoder synchronously add encountered strings while exchanging only dictionary codes.

Version
v2 · 2026-09-19 · History
Domain-specific #
2175
Domain group
Applied Sciences & Engineering
Origin domain
Computer Science & Software Engineering
Subdomain
Lossless Compression → Computer Science & Software Engineering
Aliases
LZW, Lempel-Ziv-Welch

Core Idea

Lempel–Ziv–Welch (LZW) is an adaptive lossless dictionary-compression algorithm. The encoder starts with a shared dictionary of alphabet symbols, repeatedly finds the longest dictionary phrase matching the unread input, emits that phrase’s code, and adds the phrase extended by the next symbol. The decoder reconstructs the same additions from the code stream, so the evolving dictionary itself need not be transmitted. Terry Welch published the scheme as a practical development of Lempel–Ziv parsing and emphasized its prefix-structured string table.

How would you explain it like I'm…

The Grow-Together Codebook

Imagine you and a friend each build the same secret codebook while reading a story, one word-piece at a time. When a chunk of letters shows up again, you just say its short code number instead of spelling it all out. Because you both add the same new chunks in the same order, you never have to mail your friend the codebook.

Shared Secret Shortcut List

Lempel–Ziv–Welch is a way to shrink a message without losing anything. The sender and receiver both start with a list of single letters. The sender finds the longest chunk at the front of the message that is already on the list, sends that chunk's number, and adds a new entry: that chunk plus the next letter. The receiver can work out every new entry from the numbers it gets, so both lists grow the same way. Repeated chunks become short numbers, which saves space.

Synchronized Dictionary Compression

Lempel–Ziv–Welch (LZW) is a lossless, adaptive dictionary compression algorithm. The encoder and decoder both begin with a dictionary holding every single symbol of the alphabet. The encoder repeatedly matches the longest dictionary phrase at the front of the unread input, outputs its code, and adds a new phrase made of that match plus the next symbol. The decoder sees the codes and can rebuild the exact same additions in the same order, so the dictionary itself never has to be sent. It is not just any dictionary-based compressor. It has a specific grow-by-one-symbol rule, plus one tricky case where the decoder receives a code for the entry it is still building.

 

LZW is an online, lossless dictionary coder that Terry Welch presented as a practical development of Lempel–Ziv parsing. Its string table is prefix-structured: every entry is an earlier entry extended by one symbol. Encoding works greedily. It finds the longest table match w for the unread input, emits code(w), and inserts w followed by the next symbol c. Compression comes from replacing recurring strings with fixed- or growing-width integer codes. Correctness comes from synchronization: the decoder inserts entries in the same order, using only information it has already decoded. The one special case is a received code that is not yet in the decoder's table. That happens when the code names the very entry being formed, and it resolves to the previous string plus its own first symbol. Real formats differ in initial alphabet, code-width schedule, clear codes, table-size limits, and bit packing. Encoder and decoder must agree on these choices, but they don't change the core algorithm.

Scope of Application

LZW is used where exact reconstruction, streaming operation, and modest implementation complexity matter. Historical and standardized deployments include image and document formats, archival tools, and communication systems. GIF specifies an LZW-based data stream with clear and end codes and variable code sizes; TIFF defines an LZW compression scheme with its own predictor and packing context.

The algorithm works on sequences over any agreed finite alphabet, not just text. Its effectiveness depends on repeated substrings and on whether the table grows enough to capture them before reset or saturation.

Clarity

The synchronized-table account resolves the apparent puzzle of how a decoder can interpret codes for strings never sent explicitly. After decoding a phrase, both sides know the previous phrase and the first symbol of the next; therefore both can add the same concatenation at the same dictionary index.

Manages Complexity

LZW replaces repeated variable-length strings with fixed or gradually widening codes and learns the dictionary in one pass. It needs no preliminary frequency scan and transmits no separate phrase table. A trie or hash table can locate the longest known phrase, while an array of prefix-code and trailing-symbol pairs can represent decoder entries compactly.

Abstract Reasoning

Correctness follows by a synchronization invariant: before each corresponding insertion, encoder and decoder dictionaries contain identical entries at identical codes. The encoder emits a known phrase. The decoder recovers that phrase and forms the same extension that the encoder inserted at the preceding boundary. Induction proves equality of decoded and source symbol sequences, including the constrained not-yet-defined-code case.

Knowledge Transfer

The core transfers literally across GIF, TIFF, and other streams only after their code-width and reset conventions are parameterized. A generic LZW decoder is therefore a state machine plus a format adapter, not a single universal bit parser.

The broader pattern—learn recurring chunks and replace them with references—transfers to dictionaries, memoization, and grammar-based coding. That abstraction belongs to Compression or Reuse. Calling any learned token vocabulary “LZW” is inaccurate unless synchronous phrase extension and code reconstruction remain.

Relationships to Other Abstractions

Local relationship map for Lempel–Ziv–WelchParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Lempel–Ziv–WelchDOMAINPrime abstraction: Compression — is a kind ofCompressionPRIME

Current abstraction Lempel–Ziv–Welch Domain-specific

Parents (1) — outgoing typed relations

  • Lempel–Ziv–Welch is a kind of Compression Prime

    LZW instantiates Compression by replacing repeated phrases with shorter codes while preserving lossless recovery.

Hierarchy paths (3) — routes to 3 parentless roots

Neighborhood in Abstraction Space

Lempel–Ziv–Welch sits in a sparse region of the domain-specific corpus (85th percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Unclustered & Miscellaneous (2769 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-10-25