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

Section 2.2 describes a method for solving recurrence relations which is based on analyzing the recursion tree and deriving a formula for the work done at each level. Another (closely related) method is to expand out the recurrence a few times, until a pattern emerges. For instance, let’s start with the familiar T(n)=2T(n/2)+o(n). Think of o(n) as being role="math" localid="1658920245976" <cnfor some constant , so: T(n)<2T(n/2)+cn. By repeatedly applying this rule, we can bound T(n) in terms of T(n/2), then T(n/4), then T(n/8), and so on, at each step getting closer to the value of T(.) we do know, namely .

T(1)=0(1).

T(n)2T(n/2)+cn2[2Tn/4+cn/2]+cn=4T(n/4)+2cn4[2Tn/8+cn/4]+2cn=8T(n/8)+3cn8[2Tn/16+cn/8]+3cn=16T(n/16)+4cn

.

.

.

A pattern is emerging... the general term is

T(n)2kT(n/2k)+kcn

Plugging in k=log2n, we get T(n)nT(1)+cnlog2n=0(nlogn).

(a)Do the same thing for the recurrence T(n)=3T(n/2)+0(n). What is the general kth term in this case? And what value of should be plugged in to get the answer?(b) Now try the recurrence T(n)=T(n-1)+0(1), a case which is not covered by the master theorem. Can you solve this too?

Short Answer

Expert verified

answer is not given by the question.

Step by step solution

01

Solution of part (a)

Finding the general term for the following recurrence:

Tn=3Tn/2+On

Let Oncn.

Thus, Tn can be present as follows:

Tn=3Tn/2+cn…… (1)

Tn=n/2in this formula it’s represent as follows:

Tn/23n/4+cn/2

Tn/4can be represented as follows:

Tn/23n/8+cn/4

Tn/8can be represented as follows:

Tn/83n/16+cn/8

Sub-equation (2) in equation (1). Hence,Tncan be rewritten as follows:

role="math" localid="1658982909094" Tn3n/4+cn/2+cn9n/4+3cn/2+cn9n/4+5cn/2

Equation (5) can be written as follows:

Tn32Tn/22+2cn3/22-1

The gives a detailed analysis for the formulation of solution as answer:

Tn32Tn/22+2cn3/22-19Tn/4+2cn9/4-19Tn/4+2cn5/49Tn/4+cn5/29Tn/4+5cn/2

Substitute equation in equation.

Tn93Tn/8+cn/4+5cn/227Tn/8+9cn/4+5cn/227Tn/8+19cn/4

Equation can be written as follows:

Tn33Tn/23+2cn3/23-1

Note:

Explanation for the representation of equation as equation has been represented as follows:

Tn33Tn/23+2cn3/23-127Tn/8+2cn27/8-127Tn/8+2cn19/827Tn/8+cn19/4

Substitute equation (4) in equation (7).

Tn273Tn/16+cn/8+19cn/481Tn/16+65cn/8

Equation can be written as follows:

Tn34Tn/24+2cn3/24-1

This following is an explanation for such formulation for equation into equation:

TN34Tn/24+2cn3/24-181Tn/16+2cn81/16-181Tn/16+2cn65/1681Tn/16+2cn65/1681Tn/16+65cn/8

Commonly, it will be written as follow:

Tn3kTn/2k+2cn3/2k-1

Substituting k=lognn then,

Tnnlog23Tn/2log2n+2cn3/2log2n-1nlog23Tn/2log2n+2cnnlog23/nlog22-1nlog23Tn/n1+2cnn1.58/n1-1nlog23T1+2cnn1.58-n/nnlog23T1+2cnn0.58/nnlog23T1+2cn0.58

T1can be written as o1 and neglect the constant term 2cn0.58. Hence, the above equation becomes,

Tnnlog23O1=Onlog23

Therefore, when substituting k=log2n in the general representation of Tn, the final answer Onlog23 is obtained.

02

Solution of part (b)

Finding the general kterm for the following recurrence:

Tn=Tn-1+O1

Let role="math" localid="1658987670332" o(n)cn thus, Tn it will be represented as follows:

TnTn-1+c

Tn-1can be represented as follows:

Tn-1Tn-1-1+cTn-2+c

Tn-2it will be represented as follows:

Tn-2Tn-2-1+cTn-3+c

Substitute equation (2) in equation (1). Hence,Tncan be rewritten as follows:

Tn-2Tn-2+c+cTn-2+2c

In general,Tncan be written as follow:

TnTn-k+kc

Substitute k=n in equation (5),Tncan be written as follows:

TnTn-n+ncTn=T0+nc=On

Therefore, Tn=On and it can be obtained by substituting k=n.

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

This problem illustrates how to do the Fourier Transform (FT) in modular arithmetic, for example, modulo .(a) There is a number such that all the powers ω,ω2,...,ω6 are distinct (modulo ). Find this role="math" localid="1659339882657" ω, and show that ω+ω2+...+ω6=0. (Interestingly, for any prime modulus there is such a number.)

(b) Using the matrix form of the FT, produce the transform of the sequence (0,1,1,1,5,2) modulo 7; that is, multiply this vector by the matrix M6(ω), for the value of ωyou found earlier. In the matrix multiplication, all calculations should be performed modulo 7.

(c) Write down the matrix necessary to perform the inverse FT. Show that multiplying by this matrix returns the original sequence. (Again all arithmetic should be performed modulo 7.)

(d) Now show how to multiply the polynomials and using the FT modulo 7.

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?

In justifying our matrix multiplication algorithm (Section 2.5), we claimed the following block wise property: if X and Y are n×nn matrices, and

X=[ABCD],Y=[EFGH],

where A,B,C,D,E,F,G, and H are n/2×n/2 sub-matrices, then the product XY can be expressed in terms of these blocks:

XY=[ABCD][EFGH]=[AE+BGAF+BHCE+DGCF+DH]

Prove this property.

In Section 1.2.3, we studied Euclid’s algorithm for computing the greatest common divisor (gcd) of two positive integers: the largest integer which divides them both. Here we will look at an alternative algorithm based on divide-and-conquer.

(a) Show that the following rule is true.

gcd(a,b)={2gcd(a2,b2)ifa,bareevengcd(ab2)ifaisodd,bisevengcd(a-b2,b)ifa,bareodd

(b) Give an efficient divide-and-conquer algorithm for greatest common divisor.

(c) How does the efficiency of your algorithm compare to Euclid’s algorithm if a and b are n-bit -bit integers? (In particular, since n might be large you cannot assume that basic arithmetic operations like addition take constant time.)

Question: On page 66 there is a high-level description of the quicksort algorithm.

(a) Write down the pseudocode for quicksort.

(b) Show that its worst - case running time on an array of size n is Θ(n)2.

(c) Show that its expected running time satisfies the recurrence relation.

T(n)O(n)+1ni=1n-1(Ti+Tn-i)

Then, show that the solution to this recurrence is O(nlogn).

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