Tribonacci Numbers and Tiling Counts
The Tribonacci sequence extends Fibonacci's 'sum of the last two' rule to 'sum of the last three,' and it is the natural answer to counting problems where each step can be one of three sizes instead of two.
The Fibonacci sequence answers "how many ways can I climb stairs taking 1 or 2 steps at a time?" — each count is the sum of the two before it. The Tribonacci sequence answers the same question when you're also allowed to take 3 steps at once: each term is the sum of the three preceding terms, , because your last move onto stair was a step of size 1, 2, or 3, landing you from stair , , or respectively.
With seeds , , , the sequence runs . Check — matching the table.
The same recursion counts tilings: the number of ways to tile a strip using tiles of length 1, 2, and 3 follows exactly this rule, since the last tile placed has one of those three lengths. Interview variants dress this up as step-counting, tiling, or "how many binary strings of length avoid three consecutive identical digits" — all reduce to the same three-term recursion once you identify what the "last move" could have been.
Whenever a counting problem's last step can take one of three sizes, the count satisfies a three-term recursion (Tribonacci-style): the total ways to reach is the sum of the ways to reach , , and .
Related concepts
Practice in interviews
Further reading
- Concrete Mathematics, Graham, Knuth & Patashnik