Math Fundamentals18 sections · 814 units
Open in Course

Power - Naive Approach

Loop n times

The simplest solution: start with 1, multiply by xx exactly nn times.

If n=5n = 5, you compute 1×x×x×x×x×x1 \times x \times x \times x \times x \times x. This takes O(n)O(n) time.

For small nn, this works fine. But if n=109n = 10^9, you're doing a billion multiplications. That's too slow. Can you cut the work in half somehow?