/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none} Q4E Suppose you are choosing between... [FREE SOLUTION] | 91影视

91影视

Suppose you are choosing between the following three algorithms: 鈥 Algorithm A solves problems by dividing them into five sub-problems of half the size, recursively solving each sub-problem, and then combining the solutions in linear time. 鈥

Algorithm B solves problems of size n by recursively solving two sub-problems of size n-1and then combining the solutions in constant time. 鈥 Algorithm C solves problems of size n by dividing them into nine sub-problems of size n/3, recursively solving each sub-problem, and then combining the solutions in O(n2)time.

What are the running times of each of these algorithms (in big- O notation), and which would you choose?

Short Answer

Expert verified

Running time for each algorithm are:

  • Tn=Onlg5
  • Tn=O2n

Tn=On2logn

Step by step solution

01

Basic information about each algorithm

Algorithmic A solves issues by breaking these onto five half-size sub-problems and systematically answering each one.

Algorithm B repeatedly tackles two sub-problems in size n to solve these issues of size n .

Algorithm C divides issues of size n over nine sub-problems with size n/3 and solves every sub-problem iteratively.

02

Running time calculation

  1. Algorithm A will also be expressed as
    Tn=5Tn/2+n
    by use of the Master's theorem
    b=5a=2
    Thus, Tn=Onlg5
    1. Algorithm B will be expression as
    2. Tn=2Tn-1+c
      We're having multiple sub issues for every stage, like as 2,3,8,....
      So run time will be of order:

    localid="1659070651841" Tn=O2n

    1. For Algorithm C, calculation is based on question is given as above.
      Tn=9Tn/3+n2
      So,

    b=9a=3log39=2
    Which is equal to power of constant term
    so run time will be: Tn=On2logn

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 91影视!

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 this problem we will develop a divide-and-conquer algorithm for the following geometric task.

CLOSEST PAIRInput: A set of points in the plane, {p1=(x1;y1),p2=(x2,y2),...,pn=(xn,yn)}

Output: The closest pair of points: that is, the pair PiPjfor which the distance between piand pj, that is,

(xi-xi)2+z(yi-yi)2,

is minimized.

For simplicity, assume that n is a power of two, and that all the x-coordinates role="math" localid="1659237354869" xi are distinct, as are the y-coordinates.

Here鈥檚 a high-level overview of the algorithm:

.Find a value for which exactly half the points have xi<x, and half have xi>x. On this basis, split the points into two groups, L and R.

鈥 Recursively find the closest pair in L and in R. Say these pairs are pLqLLand pRqRRwith distances dLand dR respectively. Let d be the smaller of these two distances.

鈥 It remains to be seen whether there is a point in Land a point in R that are less than distance dapart from each other. To this end, discard all points with xi<x-dor xi>x+d and sort the remaining points by y-coordinate.

鈥 Now, go through this sorted list, and for each point, compute its distance to the seven subsequent points in the list. Let pMqMbe the closest pair found in this way.

鈥 The answer is one of the three pairs role="math" localid="1659237951608" {pL,qL},{pR,qR}{pM,qM}, whichever is closest.

(a) In order to prove the correctness of this algorithm, start by showing the following property: any square of size dd in the plane contains at most four points of L.

(b) Now show that the algorithm is correct. The only case which needs careful consideration is when the closest pair is split between L and R.

(c) Write down the pseudocode for the algorithm, and show that its running time is given by the recurrence:

T(n)=2T(nl2)+0(nlogn)

Show that the solution to this recurrence is o(nlogzn).

(d) Can you bring the running time down to O(nlogn)?

Suppose we want to evaluate the polynomial P(x) = a0 + a1x + a2x2 + ... + anxn at point x.

  1. Show that the following simple routine, known as Horner鈥檚 rule, does the job and leaves the answer in z.
    z = an
    for I = n-1 down to 0 :
    z = zx + ai
  2. How many additions and multiplications does this routine use, as a function of n ? Can you find a polynomial for which an alternative method is substantially better?

A binary tree is full if all of its vertices have either zero or two children. Let Bndenote the number of full binary trees with n vertices. (a)By drawing out all full binary trees with 3, 5, or 7 vertices, determine the exact values of B3, B5, and B7. Why have we left out even numbers of vertices, like B4?

(b) For general n, derive a recurrence relation for Bn.

(c) Show by induction that Bnis (2n).

Consider the task of searching a sorted array A[1,,n] for a given element x: a task we usually perform by binary search in time O(logn) . Show that any algorithm that accesses the array only via comparisons (that is, by asking questions of the form 鈥渋s A[i]z 0?鈥), must take (logn) steps.

Find the unique polynomial of degree 4 that takes on values p(1)=2,p(2)=1,p(3)=0,p(4)=4,andp(5)=0. Write your answer in the coefficient representation.

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.