Divide and Conquer (recurrence relation problem)...

1.3k Views Asked by At

The problem:

(a) Use a divide-and-conquer approach to devise a procedure to find the largest and next-to-largest numbers in a set of $n$ distinct integers.

(b) Give a recurrence relation for the number of comparisons performed by your procedure.

(c) Solve the recurrence relation obtained in part (b).

So here's the work I did, with a, b, and c done in 1 swoop:

Consider $l_1,l_2\in\mathbb{Z}$ and let $L=\max\left\{ {l_1,l_2}\right\}$. Dividing $L$, we compare $l_1,l_2$ now and obtain $$a_n=2a_{n/2}+1$$ for $n \geq 2$ since we have are just comparing the two integers. Using known formulas for the way our $a_n$ looks, we obtain $a_n=An-1$, where if we impose the condition $a_1=1$, we obtain $A=2$ and ultimately $$a_n=2n-1.$$

I used an example in the book that was similar to this problem to come to this conclusion, but overall am incredibly confused. I have no idea if I did this correctly. If someone could verify I'm on the right/wrong path, I'd be much obliged.

1

There are 1 best solutions below

2
On

For (a), start with 2 values, they are maximum/minimum for the range. If you have $n$ values, split in two as evenly as possible, and get (recursively) largest and runner up for each part, figure out how to combine this for the full $n$ values.

For (b), from the above see what you can use as key operations (so that others are proportional in number), and set up a recurrence according to (a).