encyclopegia.org

Re-Pair

Re-Pair (short for recursive pairing) is a grammar-based compression algorithm that, given an input text, builds a straight-line program, i.e.[src] a context-free grammar generating a single string: the input text.[src] In order to perform the compression in linear time, it consumes the amount of memory that is approximately five times the size of its input.[src] The grammar is built by recursively replacing the most frequent pair of characters occurring in the text.[src] Once there is no pair of characters occurring twice, the resulting string is used as the axiom of the grammar.[src] Therefore, the output grammar is such that all rules but the axiom have two symbols on the right-hand side.[src] Re-Pair was first introduced by N.[src] J.[src] Larsson and A.[src] Moffat in 1999.[src]

Re-Pair (short for recursive pairing) is a grammar-based compression algorithm that, given an input text, builds a straight-line program, i.e.[src] a context-free grammar generating a single string: the input text.[src] In order to perform the compression in linear time, it consumes the amount of memory that is approximately five times the size of its input.[src] The grammar is built by recursively replacing the most frequent pair of characters occurring in the text.[src] Once there is no pair of characters occurring twice, the resulting string is used as the axiom of the grammar.[src] Therefore, the output grammar is such that all rules but the axiom have two symbols on the right-hand side.[src] Re-Pair was first introduced by N.[src] J.[src] Larsson and A.[src] Moffat in 1999.[src] The image on the right shows how the algorithm compresses the string w=xabcabcy123123zabc .[src] During the first iteration, the pair ab , which occurs three times in w , is replaced by a new symbol R_1 .[src] On the second iteration, the most frequent pair in the string w=xR_1cR_1cy123123zR_1c , which is R_1c , is replaced by a new symbol R_2 .[src] Thus, at the end of the second iteration, the remaining string is w=xR_2R_2y123123zR_2 .[src] In the next two iterations, the pairs 12 and R_{3}3 are replaced by symbols R_3 and R_4 respectively.[src] Finally, the string w=xR_2R_2yR_4R_4zR_2 contains no repeated pair and therefore it is used as the axiom of the output grammar.[src] num_rules_encoded = 256 // By default, the extended ASCII charset are the terminals of the grammar.[src] writeSymbol(symbol s) { bitslen = log(num_rules_encoded); // Initially 8, to describe any extended ASCII character write s in binary using bitslen bits } void encodeCFG_rec(symbol s) { if (s is non-terminal and this is the first time symbol s appears) { take rule s → X Y; write bit 1; encodeCFG_rec(X); encodeCFG_rec(Y); assign to symbol s value ++num_rules_encoded; } else { write bit 0; writeSymbol(terminal/value assigned) } } void encodeCFG(symbol s) { encodeCFG_rec(s); write bit 1; } Another possibility is to separate the rules of the grammar into generations such that a rule X \to YZ belongs to generation i iff at least one of Y or Z belongs to generation i-1 and the other belongs to generation j with j \leq i-1 .[src] Then these generations are encoded subsequently starting from generation 0 .[src] This was the method proposed originally when Re-Pair was first introduced.[src] However, most implementations of Re-Pair use the implicit encoding method due to its simplicity and good performance.[src] Furthermore, it allows on-the-fly decompression.[src]

32 sentences · 32 cited inline · 0 references stored

References

No reference rows published for this article.

Cite this article

MLA

"Re-Pair." encyclopegia.org, 2025, https://encyclopegia.org/wiki/re-pair. Accessed 25 November 2026.

Chicago

"Re-Pair." encyclopegia.org. Accessed November 25, 2026. https://encyclopegia.org/wiki/re-pair.

APA

encyclopegia.org. (2025). Re-Pair. Retrieved November 25, 2026, from https://encyclopegia.org/wiki/re-pair

Accessed November 25, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Reggiane Re.2004

stub · references available

We Have the Facts and We're Voting Yes

stub · references available

Pair of Kings

stub · references available

Giovanni Battista Re

stub · references available

coxless pair

stub · references available

A Nice Pair

stub · references available

RE 2

stub · references available

Armando Tre Re

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1321817209 · 0.5 · snapshot enwiki-001321817209

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.