Median Of Three
1. **Problem statement:** We consider a Median-of-Five variant where the input of size $n$ is partitioned into $\frac{n}{3}$ blocks of size 3 instead of 5.
2. **Part (a) - Deriving the recursive formula for time complexity $T(n)$:**
- Partition input into $\frac{n}{3}$ blocks of size 3.
- Find the median of each block, which takes constant time per block, so $O(n)$ total.
- Recursively find the median of these medians. The number of medians is $\frac{n}{3}$, so this takes $T\left(\frac{n}{3}\right)$ time.
- Partition the array around the pivot median, which is $O(n)$.
- Recursively search in one partition. From analysis similar to Median-of-Five, we know the size of the partition to search is at most $\frac{2n}{3}$.
Thus, we get the recurrence:
$$
T(n) \leq T\left(\frac{n}{3}\right) + T\left(\frac{2n}{3}\right) + cn
$$
for some constant $c > 0$.
3. **Part (b) - Solve the recurrence by assuming $T(n) \in O(n)$:**
- Suppose $T(n) \leq an$ for some constant $a > 0$.
- Substitute into the recurrence:
$$
T(n) \leq a \frac{n}{3} + a \frac{2n}{3} + cn = an + cn = n(a + c)
$$
- This inequality holds only if $a \geq a + c$, which is impossible since $c > 0$.
4. **Conclusion:**
- The assumption $T(n) \in O(n)$ does not hold for this recurrence.
- Therefore, the time complexity $T(n)$ is not linear in $n$ under the $\frac{n}{3}$ partitioning scheme.
Final answer:
- The recursive time complexity is $$T(n) \leq T\left(\frac{n}{3}\right) + T\left(\frac{2n}{3}\right) + cn$$
- It cannot be solved as $T(n) \in O(n)$, so the linear time complexity bound does not hold.