Calkin-Wilf Tree Explorer

Every rational, exactly once

CalculatorsFreeNo Signup
4.2(479 reviews)
All Tools

Loading tool...

About Calkin-Wilf Tree Explorer

A Calkin-Wilf tree explorer navigating the binary tree where root=1/1, left child of a/b = a/(a+b), right child = (a+b)/b. Every positive rational appears exactly once! Breadth-first gives the Calkin-Wilf sequence. Client-side.

Calkin-Wilf Tree Explorer Features

  • Tree navigation
  • Sequence
  • Fraction locator
  • Path finder
  • Hyperbinary
Calkin-Wilf tree: root=1/1. Left child of a/b is a/(a+b). Right child is (a+b)/b. Every positive rational appears exactly once! BFS order: 1/1, 1/2, 2/1, 1/3, 3/2, 2/3, 3/1, 1/4,... The n-th term b(n)/b(n+1) uses the Stern diatomic sequence.

How to Use

Enter fraction or index:

  • Path: Binary path from root
  • Index: Position in BFS
  • Children: Left and right

Stern Connection

The n-th fraction in BFS order is b(n)/b(n+1) where b is the Stern diatomic sequence: b(0)=0, b(1)=1, b(2n)=b(n), b(2n+1)=b(n)+b(n+1). This connects the tree to hyperbinary representations.

vs Stern-Brocot

Both trees contain every positive rational once. Stern-Brocot uses mediants (sorted order). Calkin-Wilf uses simpler rules (not sorted). Calkin-Wilf was discovered in 2000; Stern-Brocot in 1858.

Step-by-Step Instructions

  1. 1Enter fraction.
  2. 2Find path.
  3. 3Browse levels.
  4. 4Compare to Stern-Brocot.
  5. 5Check index.

Calkin-Wilf Tree Explorer — Frequently Asked Questions

How is this different from the Stern-Brocot tree?+

Both enumerate all positive rationals exactly once. Stern-Brocot: in-order traversal is sorted (great for searching). Calkin-Wilf: simpler child formula (a/(a+b) and (a+b)/b) but NOT sorted. BFS order gives the beautiful Calkin-Wilf sequence.

How to find a fraction's position?+

Start at a/b: if a < b go left (a/(b-a)), if a > b go right ((a-b)/b), if a=b you're at root. Reverse the path to get the binary index. Equivalently, the continued fraction of a/b encodes the path.

What is the Calkin-Wilf sequence?+

BFS of the tree: 1/1, 1/2, 2/1, 1/3, 3/2, 2/3, 3/1, 1/4, 4/3, 3/5, 5/2, 2/5, 5/3, 3/4, 4/1,... Each fraction a/b is followed by 1/(2⌊a/b⌋+1-a/b). Beautiful and mysterious.

Share this tool: