8,816 views
51 votes
51 votes

Exponentiation is a heavily used operation in public key cryptography. Which of the following options is the tightest upper bound on the number of multiplications required to compute $b^n \bmod{m}, 0 \leq b, n \leq m$ ?

  1. $O(\log n)$
  2. $O(\sqrt n)$
  3. $O\Biggl (\frac{n}{\log n} \Biggr )$
  4. $O(n)$

3 Answers

Best answer
59 votes
59 votes

Correct Option: A

We need to divide $n$ recursively and compute like following:

$C_1 = b^{\frac{n}{2}} \times b^{\frac{n}{2}}$. In this, we need to calculate $b^{\frac{n}{2}}$ only once.

$C_2 = b^{\frac{n}{4}} \times b^{\frac{n}{4}}$

$\vdots$

$C_k = b^2 \times b^2 \qquad \Bigg \{k = \log n$

Recurrence relation: $T(n) =T \Bigl (\frac{n}{2} \Bigr ) + O(1)$

$T(n) = O(\log n)$

edited by
28 votes
28 votes

Answer is (A)

1. First find out b^2 which will require 1 multiplication(b*b)..store the value of b^2(say in variable 'a') for further use...

2. b^4 can be find out  using a*a ie 1 multiplication, therefore total of 2 multiplication (including step 1). Store the value of b^4 in variable 'c' for further use.

3. Similarly b^8 can be calculated by c*c i.e 1 multiplication and total of 3 multiplication (including step 2)....and so on. Therefore O(log n) is the complexity for the no. of multiplications required.

edited by
6 votes
6 votes
Or You can start from $b^1$ and keep squaring  :   $ b^1 b^2 b^4 b^8 ...  b^n $

where each squaring operation is a multiplication, which is asked in the question. $= O(logn)$
edited by
Answer:

Related questions