Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

How long does the recursive multiplication algorithm (page 25) take to multiply an n -bit number by an m -bit number? Justify your answer.

Short Answer

Expert verified

The recursive multiplication algorithm takesO(m2) time.

Step by step solution

01

Recursive algorithms

The recursive function contains a call to itself. The code in recursive function refers to itself while executing the code in the function. The multiplication algorithm is defined as adding the larger number from two numbers for the count equal to the smaller number.

02

Recursive multiplication function

functionrecursivemultiplication(a,b)

Input: Two values i.e.a,c, in whichb0

Output: Final product

If b=0

Return 0

c=recursivemultiplication(a,b÷2)

If b is even:

Return 2×c

Else

Return(a+2)×c

03

Determine time complexity of recursive multiplication algorithm

Refer to recursive multiplication algorithm (page 25) in the textbook. The integerx isn -bit number andyis m-bit number. The function contains m recursive calls. The value of variable yin the multiplication algorithm is halved in each call. The testing of odd and even requiresm bit operations. So, withm recursive call andm bit operation in each recursive call, the time complexity of the algorithm is O(m2).

Therefore, the product of x and y have time complexity of O(m2).

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

The tramp steamer problem. You are the owner of a steamship that can apply between a group of port cities V . You make money at each port: a visit to city i earns you a profit of pi dollars. Meanwhile, the transportation cost from port i to port j is cij>0 .You want to find a cyclic route in which the ratio of profit to cost is maximized.

To this end, consider a directed graph G=(V,E) whose nodes are ports, and which has edges between each pair of ports. For any cycle C in this graph, the profit-to-cost ratio is

role="math" localid="1658920675878" r(c)=i,jicPiji,jicCij

Let r' be the maximum ratio achievable by a simple cycle. One way to determine r' is by binary search: by first guessing some ratio r , and then testing whether it is too large or too small. Consider any positive r>0 . Give each edge (i,j) a weight of wij=rcij-pj .

  1. Show that if there is a cycle of negative weight, then .
  2. Show that if all cycles in the graph have strictly positive weight, then r<r*.
  3. Give an efficient algorithm that takes as input a desired accuracy >0 and returns a simple cycle c for which r(C)3r*- Justify the correctness of your algorithm and analyze its running time in terms of |V|, and R=max(i,j)iE(PJCIJ) .

The kSPANNING TREE problem is the following.Input: An undirected graph G=(V,E) Output: A spanning tree of G in which each node has degree k, if such a tree exists.Show that for any k2:

  1. k SPANNING TREE is a search problem.
  2. k SPANNING TREE is NP-complete. (Hint: Start with k=2 and consider the relation between this problem and RUDRATA PATH.)

Mean and median. One of the most basic tasks in statistics is to summarize a set of observations x1,x2,,xnR by a single number. Two popular choices for this summary statistic are:

• The median, which we’ll callμ1

• The mean, which we’ll callμ2

(a) Show that the median is the value of μthat minimizes the function

i|xi-μ|

You can assume for simplicity that is odd. (Hint: Show that for any , the function decreases if you move either slightly to the left or slightly to the right.)

(b) Show that the mean is the value of μ that minimizes the function

i(xi-μ)2

One way to do this is by calculus. Another method is to prove that for any μR,

i(xi-μ)2=i(xi-μ2)2+n(μ-μ2)2

Notice how the function for μ2 penalizes points that are far from much more heavily than the function for μ1 . Thus μ2 tries much harder to be close to all the observations. This might sound like a good thing at some level, but it is statistically undesirable because just a few outliers can severely throw off the estimate of μ2 . It is therefore sometimes said that μ1 is a more robust estimator than μ2 . Worse than either of them, however, is μ , the value of μthat minimizes the function

maxi|xi-μ|

(c) Show that μ can be computed in O(n) time (assuming the numbers are xismall enough that basic arithmetic operations on them take unit time).

Show that any array of integers x[1n] can be sorted in O (n + M) time, where

role="math" localid="1659938331794" M=maxxi-minxiii

For small M, this is linear time: why doesn’t the Ω(nlogn) lower bound apply in this case?

Question: An Eulerian tourin an undirected graph is a cycle that is allowed to pass through each vertex multiple times, but must use each edge exactly once.

This simple concept was used by Euler in to solve the famous Konigsberg bridge problem, which launched the field of graph theory. The city of Konigsberg (now called Kaliningrad, in western Russia) is the meeting point of two rivers with a small island in the middle. There are seven bridges across the rivers, and a popular recreational question of the time was to determine whether it is possible to perform a tour in which each bridge is crossed exactly once. Euler formulated the relevant information as a graph with four nodes (denoting land masses) and seven edges (denoting bridges), as shown here.

Notice an unusual feature of this problem: multiple edges between certain pairs of nodes.

(a) Show that an undirected graph has an Eulerian tour if and only if all its vertices have even degree. Conclude that there is no Eulerian tour of the Konigsberg bridges.

(b) An Eulerian pathis a path which uses each edge exactly once. Can you give a similar if-and-only-if characterization of which undirected graphs have Eulerian paths?

(c) Can you give an analog of part (a) for directedgraphs?

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