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?

Short Answer

Expert verified

The final time complexity can be written as O(n3).

Step by step solution

01

Introduction

The least common multiple can be defined as the smallest factor of the two numbers and 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 the final time complexity.

02

Algorithm to compute LCM(x,y)

Consider,LCM(x,y)

Store common multiple of xandy in any variable z.

Check whether the variablez is divisible byx andy , that is, use the algorithm:

While ()

If(z%x==0&z%y==0)

Returnz

Else

z++

LCM(x,y) can be written as(x×y)÷gcd(x,y) .

03

Time complexity of the algorithm

Forx*y the time complexity of that part isO(n2) and to find GCD we need time complexity equal to O(n3). So, final time complexity can be written as O(n3).

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

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.

Show that if xis a nontrivial square root of 1 modulo N , that is if x21modNbut x±1modN, thenN must be composite. (For instance,421mod15but4±1mod15; thus 4 is a nontrivial square root of 1 modulo 15.)

The grade-school algorithm for multiplying two n-bit binary numbers x and y consist of addingtogethern copies of r, each appropriately left-shifted. Each copy, when shifted, is at most 2n bits long.
In this problem, we will examine a scheme for adding n binary numbers, each m bits long, using a circuit or a parallel architecture. The main parameter of interest in this question is therefore the depth of the circuit or the longest path from the input to the output of the circuit. This determines the total time taken for computing the function.
To add two m-bit binary numbers naively, we must wait for the carry bit from position i-1before we can figure out the ith bit of the answer. This leads to a circuit of depthΟ(m). However, carry-lookahead circuits (see
wikipedia.comif you want to know more about this) can add inΟ(logn)depth.

  1. Assuming you have carry-lookahead circuits for addition, show how to add n numbers eachm bits long using a circuit of depth Ο(lognlogm).
  2. When adding three m-bit binary numbers x+y+z, there is a trick we can use to parallelize the process. Instead of carrying out the addition completely, we can re-express the result as the sum of just two binary numbersr+s, such that the ith bits of r and s can be computedindependently of the other bits. Show how this can be done. (Hint: One of the numbers represents carry bits.)
  3. Show how to use the trick from the previous part to design a circuit of depthΟ(logn)for multiplying two n-bit numbers.

Unlike a decreasing geometric series, the sum of the1,12,13,14,15,..... diverges; that is,i=1n1i=

It turns out that, for large n , the sum of the first n terms of this series can be well approximated as

i=1n1iInn+y

where is natural logarithm (log base e=2.718...) and y is a particular constant 0.57721...... Show that

i=1n1i=θ(logn)

(Hint: To show an upper bound, decrease each denominator to the next power of two. For a lower bound, increase each denominator to the next power of 2 .)

Is the difference of 530,000and6123,456a multiple of31 ?

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