Skip to content
ExtendedSource checked

Rice Coding

Encodes nonnegative integers using quotient-remainder codes with a power-of-two divisor.

Quick Facts

Compact metadata for implementation and discovery.

Category
Compression
Difficulty
Intermediate
Family
Universal Integer Coding
Tier
Extended
Status
Verified
Review
Source Checked
Sources
1
Formulas
1
Relationships
3
Code example
Ready
Visualization
Ready

Overview

Rice coding is a Golomb coding variant that is fast to encode and decode when values follow a geometric-like distribution.

Core Concepts

quotient-remainder splitunary quotientfixed-width remaindergeometric distribution

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(log n)

Average

O(log n)

Worst

O(log n)

Space

O(1)

When to Use

  • Use when reducing storage size needs quotient-remainder split.
  • Use when the input matches the assumptions behind universal Integer Coding.

When Not to Use

  • Avoid when the data is already compressed or the format overhead exceeds the savings.
  • Avoid when a simpler algorithm gives the required result with less setup.

What It Does

  • Encodes nonnegative integers using quotient-remainder codes with a power-of-two divisor
  • Uses quotient-remainder split and unary quotient to guide the work.
  • Produces encoded stream.

Use Cases

  • Reducing storage size
  • Compressing repeated data
  • Preparing data for transmission

Inputs

  • Input byte stream
  • Coding model or dictionary state

Outputs

  • Encoded stream
  • Decoder metadata

Key Formulas (1)

Rice split

q = ⌊n / 2k⌋, r = n mod 2k
q = floor(n / 2^k), r = n mod 2^k

Splits an integer into a unary quotient and k-bit remainder.

Pseudocode

  1. 1.Prepare the inputs and state needed for Rice Coding.
  2. 2.Apply the quotient-remainder split step while the stopping condition has not been met.
  3. 3.Update intermediate state and discard invalid candidates.
  4. 4.Return encoded stream.

Canonical Example

Input
Rice Coding input with a small representative case
Output
Encoded stream
Explanation
Rice Coding applies quotient-remainder split to produce encoded stream.

Implementation Notes

  • Define bit packing and stream termination rules before optimizing compression ratio.
  • Keep the quotient-remainder split step separate enough to test independently.

Common Pitfalls

  • Encoder and decoder state must evolve in exactly the same order.
  • Forgetting to check edge cases can make Rice Coding look correct on only ideal inputs.

Interactive Mechanism Walkthrough

Sequence Window & Automaton Alignment

Show symbols being transformed into codes and reconstructed by the decoder state.

Input:ABABABCABAB
Window:ABAB
Step 1 of 4: Prepare the inputs and state needed for Rice Coding.
compression-mechanism

Notes

Rice Coding should be used with the assumptions and tradeoffs of universal Integer Coding in mind.

Sources (1)

What each reference supports for this entry.

Introduction to Data Compression

Book

Compression reference for Rice Coding Golomb/Rice integer coding and quotient-remainder representations.

Explore Next

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

Alternative toElias Delta Coding

Both are variable-length integer coding methods.

Variant ofGolomb Coding

Rice coding specializes Golomb coding to power-of-two parameters.

Tags

CompressionEncodingInteger DataEntropy Coding