Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

GATE | Gate IT 2007 | Question 17

  • Last Updated : 28 Jun, 2021

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 bn mod m,0≤b,n≤m ?
(A) O(logn)
(B) O(√n)
(C) O(n/logn)
(D) O(n)

Answer: (A)


This Problem can be solved using Divide And Conquer Paradigm

Algorithm :

Binary_exp(b,n)                            // Compute bn mod m


    if(n == 0)

        Return 1;

    Else if(n == 1)

        Return b mod m;



        Half = Binary_exp(b,n/2);

        if(n%2 == 0)                                // n is even

            Return (Half*Half) mod m;

        Else                                    // n is odd

            Return (((Half*Half) mod m)*n) mod m;



Recurrence Relation for computing the time complexity of the above given algorithm is
T(n) = T(n/2) + constant = (log2n)

This solution is contributed by Pranjul Ahuja.

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!