/*! 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} Q3E Section 2.2 describes a method f... [FREE SOLUTION] | 91影视

91影视

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鈥檚 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鈥檚 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 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

Question: Use the divide-and-conquer integer multiplication algorithm to multiply the two binary integers 10011011and10111010 and .

Question: You are given an infinite array A[]in which the first n cells contain integers in sorted order and the rest of the cells are filled with . You are not given the value of n. Describe an algorithm that takes an integer x as input and finds a position in the array containing x, if such a position exists, in O(log n) time. (If you are disturbed by the fact that the array A has infinite length, assume instead that it is of length n, but that you don鈥檛 know this length, and that the implementation of the array data type in your programming language returns the error message whenever elements A[i]withi>n are accessed.)

A kway merge operation. Suppose you have ksorted arrays, each with nelements, and you want to combine them into a single sorted array ofkn elements.

(a)Here鈥檚 one strategy: Using the merge procedure from Section 2.3, merge the first two arrays, then merge in the third, then merge in the fourth, and so on. What is the time complexity of this algorithm, in terms of kand n?

(b) Give a more efficient solution to this problem, using divide-and-conquer.

An array A[1...n] is said to have a majority element if more than half of its entries are the same. Given an array, the task is to design an efficient algorithm to tell whether the array has a majority element, and, if so, to find that element. The elements of the array are not necessarily from some ordered domain like the integers, and so there can be no comparisons of the form 鈥 is A[i]>A[j] ?鈥. (Think of the array elements as GIF files, say.) However you can answer questions of the form: 鈥渋s ..?鈥 in constant time.

(a) Show how to solve this problem in O(nlogn) time. (Hint: Split the array A into two arrays A1and A2of half the size. Does knowing the majority elements of A1and A2help you figure out the majority element of A? If so, you can use a divide-and-conquer approach.)

(b) Can you give a linear-time algorithm? (Hint: Here鈥檚 another divide-and-conquer approach:鈥 Pair up the elements of A arbitrarily, to get n/2 pairs鈥 Look at each pair: if the two elements are different, discard both of them; if they are the same, keep just one of them . Show that after this procedure there are at most n/2 elements left, and that they have a majority element if A does.)

In our median-finding algorithm (Section 2.4), a basic primitive is the split operation, which takes as input an array S and a value V and then divides S into three sets: the elements less than V , the elements equal to V , and the elements greater than V . Show how to implement this split operation in place, that is, without allocating new memory.

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.