1 of 3
ryan
  • 4.5k
  • 1
  • 15
  • 41

There may be times when you come across a strange recurrence like this: $$T(n) = \begin{cases} c & n < 7\\ 2T\left(\frac{n}{5}\right) + 4T\left(\frac{n}{7}\right) + cn & n\geq 7 \end{cases}$$ If you're like me, you'll realize you can't use the Master Theorem and then you make think, "hmmm... maybe a recurrence tree analysis could work." Then you'd realize that the tree starts to get gross really fast. After some searching on the internet you see the Akra-Bazzi method will work! Then you actually start to look into it and realize you don't really want to do all the math. If you've been like me up till this point, you'll be excited to know there's an easier way.


The Uneven Split Theorem Part 1

Let $c$ and $k$ be positive constants.

Then let $\{a_1, a_2, \ldots, a_k\}$ be positive constants such that $\sum_1^k a_i < 1$.

We also must have a recurrence of the form (like our example above):

$$\begin{align} T(n) & \leq c & 0 < n < \max\{a_1^{-1}, a_2^{-1}, \ldots, a_k^{-1}\}\\ T(n) & \leq cn + T(a_1 n) + T(a_2 n) + \dots T(a_k n) & n \geq \max\{a_1^{-1}, a_2^{-1}, \ldots, a_k^{-1}\} \end{align}$$

Claim

Then I claim $T(n) \leq bn$ where $b$ is a constant (e.g. asymptotically linear) and:

$$b = \frac{c}{1 - \left(\sum_1^k a_i\right)}$$

Proof by Induction

Basis: $n < \max\{a_1^{-1}, a_2^{-1}, \ldots, a_k^{-1}\} \implies T(n) \leq c < b < bn$

Induction: Assume true for any $n' < n$, we then have

$$\begin{align} T(n) & \leq cn + T(\lfloor a_1 n \rfloor) + T(\lfloor a_2 n \rfloor) + \dots + T(\lfloor a_k n \rfloor)\\ & \leq cn + b \lfloor a_1 n \rfloor + b \lfloor a_2 n \rfloor + \dots + b \lfloor a_k n \rfloor\\ & \leq cn + b a_1 n + b a_2 n + \dots + b a_k n\\ & = cn + bn \sum_1^k a_i\\[0.5em] & = \frac{cn - cn \sum_1^k a_i }{1 - \left(\sum_1^k a_i\right)} + \frac{cn \sum_1^k a_i}{1 - \left(\sum_1^k a_i\right)}\\[0.5em] & = \frac{cn}{1 - \left(\sum_1^k a_i\right)}\\ & = bn & \square \end{align}$$

Then we have $T(n) \leq bn \implies T(n) = O(n)$.

We also know $T(n) = \Omega(n)$ by the recurrence definition, therefore $T(n) = \Theta(n)$.

Example

$$T(n) = \begin{cases} c & n < 7\\ 2T\left(\frac{n}{5}\right) + 4T\left(\frac{n}{7}\right) + cn & n\geq 7 \end{cases}$$ We first verify the coefficients inside the recursive calls sum to less than one: $$\begin{align} 1 & > \sum_1^k a_i \\ & = \frac{1}{5} + \frac{1}{5} + \frac{1}{7} + \frac{1}{7} + \frac{1}{7} + \frac{1}{7}\\[0.5em] & = \frac{2}{5} + \frac{4}{7}\\[0.5em] & = \frac{34}{35} \end{align}$$

We next verify that the base case is less than the max of the inverses of the coefficients: $$\begin{align} n & < \max\{a_1^{-1}, a_2^{-1}, \ldots, a_k^{-1}\}\\ & = \max\{5, 5, 7, 7, 7, 7\}\\ & = 7 \end{align}$$

With these conditions met, we know $T(n) \leq bn$ where $b$ is a constant equal to: $$\begin{align} b &= \frac{c}{1 - \left(\sum_1^k a_i\right)}\\[0.5em] &= \frac{c}{1 - \frac{34}{35}}\\[0.5em] &= 35c \end{align}$$ Therefore we have: $$\begin{align} T(n) & \leq 35cn\\ \land\; T(n) & \geq cn\\ \therefore T(n) & = \Theta(n) \end{align}$$


The Uneven Split Theorem Part 2

Similarly we can prove a bound for when $\sum_1^k = 1$. The proof will follow much of the same format:

Let $c$ and $k$ be positive constants such that $k > 1$.

Then let $\{a_1, a_2, \ldots, a_k\}$ be positive constants such that $\sum_1^k a_i = 1$.

We also must have a recurrence of the form (like our example above):

$$\begin{align} T(n) & \leq c & 0 < n < \max\{a_1^{-1}, a_2^{-1}, \ldots, a_k^{-1}\}\\ T(n) & \leq cn + T(a_1 n) + T(a_2 n) + \dots T(a_k n) & n \geq \max\{a_1^{-1}, a_2^{-1}, \ldots, a_k^{-1}\} \end{align}$$

Claim

Then I claim $T(n) \leq \alpha n \log_k n + \beta n$ (we choose $\log$ base $k$ because $k$ will be the branching factor of the recursion tree) where $\alpha$ and $\beta$ are constants (e.g. asymptotically linearithmic) such that:

$$\beta = c$$ and $$\alpha = \frac{c}{\sum_1^k a_i \log_k a_i^{-1}}$$

Proof by Induction

Basis: $n < \max\{a_1^{-1}, a_2^{-1}, \ldots, a_k^{-1}\} \implies T(n) \leq c = \beta < \alpha n \log_k n + \beta n$

Induction: Assume true for any $n' < n$, we then have

$$\begin{align} T(n) & \leq cn + T(\lfloor a_1 n \rfloor) + T(\lfloor a_2 n \rfloor) + \dots + T(\lfloor a_k n \rfloor)\\ & \leq cn + \sum_1^k (\alpha a_i n \log_k a_i n + \beta a_i n)\\ & = cn + \alpha n\sum_1^k (a_i \log_k a_i n) + \beta n\sum_1^k a_i\\ & = cn + \alpha n\sum_1^k \left(a_i \log_k \frac{n}{a_i^{-1}}\right) + \beta n\\ & = cn + \alpha n\sum_1^k (a_i (\log_k n - \log_k a_i^{-1})) + \beta n\\ & = cn + \alpha n\sum_1^k a_i \log_k n - \alpha n\sum_1^k a_i \log_k a_i^{-1} + \beta n\\ & = \alpha n\sum_1^k a_i \log_k n + \beta n\\ & = \alpha n \log_k n + \beta n & \square \end{align}$$

Then we have $T(n) \leq \alpha n \log_k n + \beta n \implies T(n) = O(n \log n)$.

Example

Let's modify that previous example we used just a tiny bit: $$T(n) = \begin{cases} c & n < 35\\ 2T\left(\frac{n}{5}\right) + 4T\left(\frac{n}{7}\right) + T\left(\frac{n}{35}\right)+ cn & n \geq 35 \end{cases}$$

We first verify the coefficients inside the recursive calls sum to less than one: $$\begin{align} 1 & = \sum_1^k a_i \\ & = \frac{1}{5} + \frac{1}{5} + \frac{1}{7} + \frac{1}{7} + \frac{1}{7} + \frac{1}{7} + \frac{1}{35}\\[0.5em] & = \frac{2}{5} + \frac{4}{7} + \frac{1}{35}\\[0.5em] & = \frac{35}{35} \end{align}$$

We next verify that the base case is less than the max of the inverses of the coefficients: $$\begin{align} n & < \max\{a_1^{-1}, a_2^{-1}, \ldots, a_k^{-1}\}\\ & = \max\{5, 5, 7, 7, 7, 7, 35\}\\ & = 35 \end{align}$$

With these conditions met, we know $T(n)\leq \alpha n \log n + \beta n $ where $\beta = c$ and $\alpha$ is a constant equal to: $$\begin{align} b &= \frac{c}{\sum_1^k a_i \log_k a_i^{-1}}\\[0.5em] &= \frac{c}{\frac{2 \log_7 5}{5} + \frac{4 \log_7 7}{7} + \frac{\log_7 35}{35}}\\[0.5em] &\approx 1.048c \end{align}$$ Therefore we have: $$\begin{align} T(n) & \leq 1.048cn\log_7 n + cn\\ \therefore T(n) & = O(n \log n) \end{align}$$

ryan
  • 4.5k
  • 1
  • 15
  • 41