ANALYS OF ALGORITHMS
ANALYS OF ALGORITHMS COT 5405
Popular in Course
Popular in OTHER
This 13 page Class Notes was uploaded by Carlo Monahan on Friday September 18, 2015. The Class Notes belongs to COT 5405 at University of Florida taught by Sanjay Ranka in Fall. Since its upload, it has received 7 views. For similar materials see /class/206636/cot-5405-university-of-florida in OTHER at University of Florida.
Reviews for ANALYS OF ALGORITHMS
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 09/18/15
ANALYSIS OF ALGORITHMS Sanjay Ranka September 13 2002 Divide and Conquer Part ll Divide and Conquer Method At each level of recursion 1 Divide the problem into a number of subproblems 2 Conquer the problems by solving them recursively or for small subproblems solve in a straightforward manner 3 Combine the solutions to the subproblem into the solution of the original problem Merge Sort Sanjay Ranka 1 COT 5405 Divide and Conquer Part ll Maximum Subsequence Problem Given possibly negative integers am a2 an nd the maximum value of the Sim ak for some values of 2 and j 1 g 2 g j g n For convenience the maximum subsequence sum is 0 if all the integers are negative As an example for inputs 4 W the answer is 22 Sanjay Ranka 2 COT 5405 Divide and Conquer Part II Maximum Subsequence Problem Algorithm 1 Step 1 Set MAXSUM 0 Step 2 Calculate 8Z j zigz al and update the MAXSUM by 3z j if 3z j gt MAXSUM for 1 g z gj g 71 Step 3 MAXSUM is the answer COT 5405 Sanjay Ranka Divide and Conquer Part II Analysis In sij we sum j 2 1 terms Therefore the complexity of the algorithm is n n j n n 2 221 2120 z1 z jZ n nz 1n z 2 A 2391 2 1 n 3214M 3n 2 2n 3Z 2 2 W 0013 Note that sij zigz al sij 1 am Sanjay Ranka 4 COT 5405 Divide and Conquer Part ll Maximum Subsequence Problem Algorithm 2 We should be able to nd the M AX S U M in either the left half or the right half of the sequence For example in 4 10 12 5 7 7 8 3 1 the MAXSUM of the rst half is 22 and M AX S U M of the second half is 12 Step 1 Divide the sequence in two equal halves Step 2 Find the MAXSUML of the left half Via this recursive method Step 3 Find the M AX SU M R of the right half Via this recursive rnethod COT 5405 Sanjay Ranka Divide and Conquer Part II Step 4 Find MAXSUM maxMAXSUML MAXSUMR Sanjay Ranka 6 COT 5405 Divide and Conquer Part ll Flaw What happens if the maximum sum is due to terms in the middle of of the sequence as m the following example 4 3 5 2 7 1 2 6 2 Here M AX S U M L is 6 due to sum of rst three terms M AX SU M R is 8 due to sum of 6th and 7th terms and M AX S U M is 11 due to sum of terms 1 through 7 Sanjay Ranka 7 COT 5405 Divide and Conquer Part 11 Maximum Subsequence Problem Algorithm 3 Step 1 Divide the sequence in two equal halves Set m L1n2j Step 2 Find the MAXSUML of the left half Via this recursive method Step 3 Find the M AX SU M R of the right half Via this recursive method Step 4a Set MAXSUMBL 0 For 2 m set BORDERm L am and for 239 m 1 1 Sanjay Ranka 8 COT 5405 Divide and Conquer Part ll calculate BORDERQ L BORDERQ 1 L am Step 4b If BORDERQ L gt MAXSUMBL then MAXSUMBL BORDERQ L Step 5 As step 4 except for the right half of the sequence Step 6 Finally M AX S U M inaxMAXSUML MAXSUMR MAXSUMBL MAXSUMBR Analysis If Tn denotes the total number of basic operations of addition then Tn 2Tn 2 71 Here we have ignored the costs of managing of the stacks Sanjay Ranka 9 COT 5405 Divide and Conquer Part II assignments etc The term 71 represents the cost of adding sums from the border to the edges Solution of this equation With T1 1 gives Tn 71 lg n n Sanjay Ranka 10 COT 5405 Divide and Conquer Part ll Multiplication of two numbers Let U Ugn1UQn2 u1u02 and V U2n 1U2n 2 U11Jo2 and our goal is to nd U gtlt V Ordinary multiplication requires execution time 012 Sanjay Ranka ll COT 5405
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'