A positive integer N is a power if it is of the formqk , where q,role="math" localid="1658399000008" k are positive integers and k>1.

(a) Give an efficient algorithm that takes as input a number and determines whether it is a square, that is, whether it can be written asq2 for some positive integer q. What is the running time of your algorithm?

(b) Show that if N=qk (with role="math" localid="1658399171717" N,q , andk all positive integers), then either role="math" localid="1658399158890" klogNorN=1.

(c) Give an efficient algorithm for determining whether a positive integerN is a power. Analyze its running time.

Short Answer

Expert verified
  1. It is havingO(log2n) iterations and the total running time of the algorithm is O(n3).
  2. Ifq=1then, the value of Nmust equal to1 .
  3. The running time complexity of the given algorithm is O(n6).

Step by step solution

01

Introduction

The running time complexity can be defined as the total amount of time taken to complete the process. It generally analyzes the time taken at each step and finally it computes for the final time complexity.

02

(a) Algorithm to find whether the input number N is a square or not

Let’s consider thatN is having nbits.

So, we are performing a binary search on the given ‘ n’ interval [2n-1,1].

It helps me to analyze that it is having a number that isq2=N .

For each iteration,

It generally takes timeO(n2) to square of the current element.

It takesO(n) to analyze and compare the result with N.

So, it is havingO(log2n) iterations and the total running time of the algorithm is O(n3).

03

(b) If N=qk  then prove either  k≤log N or N=1

We have, N=qk.

Taking log both side

logN=logqk

We can write this expression as,

logN=klogqk=logN/logq

k=logN/logq

forallq>1,we have

klogN

Ifq=1then, the value ofN must equal to 1.

04

(c) Algorithm for determining whether a positive integer N is a power

For the given question, we can use the same algorithm from part (a).

But, instead of squaring the number, we have to raise numbers to power ‘ k’ and we need to check if we get the value of N.

It takesO(n) iterations as from

for(i=1tok(inn))

Time takenO(k2×n2)

So, this algorithm takes time O(k2×n3).

If the value of the power isN then, we have to compute for allk<=logN<=n .

Therefore, the running time complexity of the given algorithm is O(n6).

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Quadratic residues. Fix a positive integer N. We say that a is a quadratic residue modulo N ifthere exists a such that ax2modN.
(a) Let N be an odd prime and be a non-zero quadratic residue modulo N. Show that there are exactly two values in{0,1,....,N-1} satisfying x2amodN.
(b) Show that if N is an odd prime, there are exactly(N+1)2 quadratic residues in {0,1,...,N-1}.
(c) Give an example of positive integers a and N such thatx2amodNhas more than two solutions in {0,1,...,N-1}.

Give an efficient algorithm to compute the least common multiple of two n-bit numbers x and y, that is, the smallest number divisible by bothx and y. What is the running time of your algorithm as a function of n?

Digital signatures, continued.Consider the signature scheme of Exercise 1.45.

(a) Signing involves decryption, and is therefore risky. Show that if Bob agrees to sign anything he is asked to, Eve can take advantage of this and decrypt any message sent by Alice to Bob.

(b) Suppose that Bob is more careful, and refuses to sign messages if their signatures look suspiciously like text. (We assume that a randomly chosen messagethat is, a random number in the range{1,...,N-1} is very unlikely to look like text.) Describe a way in which Eve can nevertheless still decrypt messages from Alice to Bob, by getting Bob to sign messages whose signatures look random.

Show that if a has a multiplicative inverse modulo N, then this inverse is unique (modulo N).

In the RSA cryptosystem, Alice’s public key (N,e)is available to everyone. Suppose that her private key d is compromised and becomes known to Eve. Show that e=3if (a common choice) then Eve can efficiently factor N.

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free