Factorial sequence

O(n)

The factorial of a non-negative integer k is the product of all positive integers up to k, written k!. Starting from 0! = 1 (the empty product), each subsequent term is obtained by multiplying the previous factorial by the next integer. Factorials grow extremely fast: 16! ≈ 2 × 10¹³. They appear throughout combinatorics, probability, and analysis — the number of ways to arrange n distinct objects is exactly n!.

Sequence
Press ▶ to run
Edit the input and press Play

How it works

  1. Initialize the array with [1], representing 0! = 1
  2. For each k from 1 to n, multiply the previous value by k to get k!
  3. Append k! to the array and highlight the new term
  4. Mark the final term n! green when the sequence is complete

Pseudocode

1factorial(n):                        # O(n)2  result ← [1]        # 0! = 13  for k = 1 to n:4    result.push(result.last * k)     # k! = (k-1)! × k5  return result