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

Question: Solve the following recurrence relations and give a bound for each of them.

(a)T(n)=2T(n/3)+1(b)T(n)=5T(n/4)+n(c)T(n)=7T(n/7)+n(d)T(n)=9T(n/3)+n2(e)T(n)=8T(n/2)+n3(f)T(n)=49T(n/25)+n(3/2)logn(g)T(n)=T(n-1)+2(h)T(n)=T(n-1)+nc,whereisaconstant(i)T(n)=T(n-1)+cn,whereissomeconstant(j)T(n)=2T(n-1)+1(k)T(n)=T(n)+1

In Section 2.1 we described an algorithm that multiplies two n-bit binary integers x and y in time na, where a=log23. Call this procedure fast multiply (x,y).

(a) We want to convert the decimal integer 10n(a 1 followed by n zeros) into binary. Here is the algorithm (assume n is a power of 2):

function pwr2bin(n)

if n = 1: return10102

else:

z= ???

return fastmultiply(z,z)

Fill in the missing details. Then give a recurrence relation for the running time of the algorithm, and solve the recurrence.

(b) Next, we want to convert any decimal integer x with n digits (where n is a power of 2) into binary. The algorithm is the following:

function dec2bin(x)

if n=1: return binary [ x ]

else:

split x into two decimal numbers xt,xRwith n/2 digits each

return ???

Here binary [.] is a vector that contains the binary representation of all one-digit integers. That is, binary role="math" localid="1659333641173" [0]=02, binary [1]=12, up to binary [9]=10012. Assume that a lookup in binary takes 0(1) time. Fill in the missing details. Once again, give a recurrence for the running time of the algorithm, and solve it.

What is the sum of the nth roots of unity? What is their product if n is odd? If n is even?

A linear, time-invariant system has the following impulse response:


(a) Describe in words the effect of this system.

(b) What is the corresponding polynomial

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 “is A[i]z 0?”), must take Ω(logn) steps.

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