← Back to Games

Power Splitter

Compare O(n) vs O(log n) exponentiation!

210 = ?
0
Linear Steps
0
Fast Steps

🐢 Linear O(n)

Multiply n times

🚀 Fast O(log n)

Divide & Conquer

📐 Fast Exponentiation Formula

pow(a, n):

  if n == 0: return 1

  half = pow(a, n/2)

  result = half × half

  if n is odd: result *= a

  return result


Key insight: a^n = (a^(n/2))² when n is even

And a^n = a × (a^(n/2))² when n is odd