Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. In the maximum subarray problem, where the input is an array of length n, give a condition under which the output of the FIND-MAXIMUM-SUBARRAY

1. In the maximum subarray problem, where the input is an array of length n, give a condition under which the output of the FIND-MAXIMUM-SUBARRAY algorithm is ( i, i+1, sum ) for some index "i" and a positive value "sum".

2. Suppose that in the maximum subarray problem the input is an array such that the values A[ i ] alternate between positive and negative (say, A[ 1 ] > 0, A[ 2 ] 0, A[ 4 ]

(i) ( i, i, sum )

(ii) ( i, i+1, sum )

(iii) ( i, i+2, sum )

for some index i and positive value sum?

Argue why or why not.

3. Suppose that a divide and conquer algorithm for multiplication of n x n matrices is found such that it requires 6 multiplications and 31 additions of n/2 x n/2 submatrices. Write the recurrence for the running time T(n) of this algorithm and find the order of T(n).

image text in transcribed

Please Help i'm lost.

image text in transcribed

FIND-MAXIMUM-SUBARRAY(A, low, high) 1 if high == low 2 Il base case: only one element return (low, high, Alow]) 3 else mid = |(low + high)/2] (left-low, left-high, left-sum) = FIND-MAXIMUM-SUBARRAY(A, low, mid) (right-low, right-high, right-sum) = FIND-MAXIMUM-SUBARRAY(A, mid + 1, high) (cross-low, cross-high, cross-sum) = FIND-MAX-CROSSING-SUBARRAY(A, low, mid, high) if left-sum > right-sum and left-sum > cross-sum return (left-low, left-high, left-sum) elseif right-sum > left-sum and right-sum > cross-sum return (right-low, right-high, right-sum) 11 else return (cross-low, cross-high, cross-sum) FIND-MAX-CROSSING-SUBARRAY(A, low, mid, high) 1 left-sum = -2 2 sum = 0 3 for i = mid downto low sum = sum + A[i] if sum > left-sum left-sum = sum max-left = i 8 right-sum = - 9 sum = 0 10 for j = mid + 1 to high sum = sum + A[j] if sum > right-sum 13 right-sum = sum 14 max-right = j 15 return (max-left, max-right, left-sum + right-sum) 12

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions

Question

Describe structured programming?

Answered: 1 week ago