Skip to content
Official PYQ · 1999

GATE CS 1999 Q1.16 — Asymptotic Worst Case Time and Space Complexity

Explain with AI

If nn is a power of 22, then the minimum number of multiplications needed to compute ana^n is

Choose one option
View worked solution

Answer: A

We can compute ana^n efficiently using the repeated squaring method (also known as exponentiation by squaring).

Let n=2kn = 2^k for some non-negative integer kk. We can compute the powers of aa sequentially as follows:

  • a2=a⋅aa^2 = a \cdot a   (1 multiplication)
  • a4=(a2)2a^4 = (a^2)^2   (2 multiplications)
  • a8=(a4)2a^8 = (a^4)^2   (3 multiplications)
  • …\dots
  • a2k=(a2k−1)2a^{2^k} = (a^{2^{k-1}})^2   (kk multiplications)

Since n=2kn = 2^k, taking the logarithm on both sides gives:

k=log⁡2nk = \log_2 n

Thus, the minimum number of multiplications required to compute ana^n when nn is a power of 22 is log⁡2n\log_2 n.

Correct Option: A

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Asymptotic Worst Case Time and Space Complexity questions