This is the question I’m trying to solve:
The following divide-and-conquer algorithm is proposed for finding the simultaneous maximum and minimum:
-
If there is one item, it is the maximum and minimum
-
if there are two items, then compare them and in one comparison you can find the maximum and minimum.
-
Otherwise, split the input in two halves, divided as evenly as possibly (if N is odd, one of the two halves will have one more element than the other).
- Recursively find the maximum and minimum of each half, and then in two additional comparisons produce the maximum and minimum for the entire problem.
(b) Suppose N is of the form 3 + 2k. What is the exact number of comparisons used by this algorithm?
for this point (b), I tried to find a recurrence equation to solve but it didn’t work.
I’ve tried
T(n)= T(n/2+1) + T(n/2) + 3
where three is the minimum cost when I try 3 inputs.
any help?
Your recurrence equation should not have a term for the special case of n = 3. The algorithm gives you these facts:
That should be all you need to work out the answer.