Himanshu S.

asked • 07/27/22

2. The following algorithm is a divide-and-conquer algorithm for finding the maximum value in array A[1..n].

Function maximum(x,y)

{ return maximum in A[x..y]}

1.                 if y - x £ 1 then return (max(A[x],A[y]))

2.                 else

3.                 max1 <--- maximum(x, [(x + y) / 2] )

4.                 max2 <--- maximum( [(x + y) / 2] + 1 , y)

5.                 return(max(max1, max2)   


Give a recurrence equation for the worst-case number of comparisons used by maximum (1, n), and solve this recurrence equation, (you may assume that n is a power of 2)

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.