Skip to content
SpecializedSource checked

Prediction by Partial Matching

Compresses by predicting the next symbol from recent context.

Quick Facts

Compact metadata for implementation and discovery.

Category
Compression
Difficulty
Advanced
Family
Statistical Compression
Tier
Specialized
Status
Verified
Review
Source Checked
Sources
1
Formulas
1
Relationships
3
Code example
Not ready
Visualization
Ready
Aliases
PPM

Overview

Prediction by Partial Matching builds context models of different lengths and uses them to drive entropy coding.

Core Concepts

context predictionprobability modelstatistical compressionsymbol representationlossless decodingstream encoding

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(n)

Average

O(nk)

Worst

O(nk)

Space

O(km)

When to Use

  • Use Prediction by Partial Matching when you need to model recent symbol contexts.
  • Use it for text compression with inputs like symbol stream.
  • Use it when the data has repetition, predictable structure, or symbol frequency imbalance.
  • Use it when the Statistical Compression tradeoff is acceptable for the problem size.

When Not to Use

  • Avoid it when small inputs or already compressed data would make metadata larger than the savings.
  • Avoid it when the required output is not compressed stream with model updates.

What It Does

  • Models recent symbol contexts
  • Predicts probabilities for upcoming symbols

Use Cases

  • Text compression
  • Adaptive statistical compression
  • Compression research baselines

Inputs

  • Symbol stream
  • Maximum context length

Outputs

  • Compressed stream with model updates

Key Formulas (1)

Context probability

P(symbol | context) = count(context + symbol) / count(context)
P(symbol | context) = count(context + symbol) / count(context)

Estimates the next-symbol probability from recent matching context, with shorter-context fallback in practice.

Pseudocode

  1. 1.Track contexts from recent symbols
  2. 2.Estimate probabilities for the next symbol
  3. 3.Fall back to shorter contexts when needed
  4. 4.Entropy-code the symbol from the chosen model
  5. 5.Update context counts

Canonical Example

Input
text = 'AAAABBBCCDAA'
Output
compressed representation with repeated runs or shorter codes
Explanation
Prediction by Partial Matching: The algorithm replaces predictable or repeated structure with a more compact representation.

Implementation Notes

  • Keep the input contract explicit: Symbol stream; Maximum context length.
  • Use this step as the implementation spine: Track contexts from recent symbols.
  • Then preserve the next state change: Estimate probabilities for the next symbol.
  • Keep encoder and decoder tests paired so every compressed sample round-trips exactly.

Common Pitfalls

  • PPM can compress text well but uses more memory than simpler dictionary methods.
  • Forgetting that the decoder needs the same model, dictionary, or metadata used by the encoder.
  • Returning compressed stream with model updates without handling empty, invalid, or boundary inputs.

Interactive Mechanism Walkthrough

Sequence Window & Automaton Alignment

Show recent characters selecting a probability model for the next symbol.

Input:ABABABCABAB
Window:ABAB
Step 1 of 5: Track contexts from recent symbols
context-model

Notes

Prediction by Partial Matching operates in O(nk) time and O(km) space within the Statistical Compression family. Key governing relation: P(symbol | context) = count(context + symbol) / count(context). Often compared with Arithmetic Coding and Brotli.

Sources (1)

What each reference supports for this entry.

Partial String Matching Compression

Paper

Original reference for prediction by partial matching, adaptive contexts, and arithmetic-coded symbol probabilities.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Often paired withArithmetic Coding

PPM commonly uses arithmetic coding to encode context probabilities.

Alternative toHuffman Coding

PPM models context probabilities rather than only static symbol frequencies.

Related Algorithms

Tags

CompressionPredictive CodingEntropy Coding