Justify the correctness of the recursive division algorithm given in page 25, and show that it takes time O(n2)onn- bit inputs.

Short Answer

Expert verified

Recursive division algorithm can be defined as dividing a number from another number which needs to satisfy the condition as,Dividend=Divisor*quotient+Remainder.

Step by step solution

01

Introduction

A recursive function is a piece of code that executes by referencing itself. Simple or complex recursive functions are both possible. They enable more effective code authoring, such as the listing or compilation of collections of integers, strings, or other variables using a single repeated procedure.

02

Recursive Function

Let the function is given as, recursive_division(a,b).

Enter two n-bit integersaandb , where b1.

Final output is quotient and remainder of a recursive_division by b.

If a=0:return(q,r)=(0,0)

role="math" localid="1658389148708" (q,r)=recursive_division(ba÷2c,b)q=2×q,r=2×r

If x is odd :r=r+1

If ry

r=ry,q=q+1return(q,r)

03

Final answer

So, the recursive function will get call up to 2 times in the given function n. So, time complexity of the given function is O(n2)forn bits input.

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

A d-ary tree is a rooted tree in which each node has at most dchildren. Show that any d-ary tree with n nodes must have a depth ofΩ(lognlogd) .Can you give a precise formula for the minimum depth it could possibly have?

If p is prime, how many elements of{0,1,...pn-1} have an inverse modulopn ?

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.

Show that any binary integer is at most four times as long as the corresponding decimal integer. For very large numbers, what is the ratio of these two lengths, approximately?

How many integers modulo113 have inverses?(Note:113=1331)

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