Skip to content

Commit

Permalink
#123 4.3-2
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtask committed Mar 15, 2024
1 parent 6e07e87 commit 1f93294
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion chapter4/sections/3/2.tex
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
\workinprogress % TODO
We'll instead consider the recurrence $T(n)=4T(n/2)+\Theta(n)$, of which the original recurrence is a special case, and we'll show that $T(n)=O(n^2)$.

Our first guess is that $T(n)\le cn^2$ for all $n\ge n_0$, where $c$, $n_0>0$ are constants.
Letting $n\ge2n_0$ and substituting the inductive hypothesis applied to $T(n/2)$, yields
\begin{align*}
T(n) &\le 4c(n/2)^2+\Theta(n) \\
&= cn^2+\Theta(n),
\end{align*}
but that does not imply that $T(n)\le cn^2$ for any choice of $c$ and for any function represented by the $\Theta(n)$ term.

Let's then improve our guess by subtracting a lower-order term: $T(n)\le cn^2-dn$, where $d\ge0$ is another constant.
Assuming that $T(n/2)\le c(n/2)^2-d(n/2)$, we now have
\begin{align*}
T(n) &\le 4(c(n/2)^2-d(n/2))+\Theta(n) \\
&= cn^2-2dn+\Theta(n) \\
&= cn^2-dn-(dn-\Theta(n)) \\
&\le cn^2-dn,
\end{align*}
where the last step holds as long as for $n\ge2n_0$ the quantity $dn$ dominates the anonymous function hidden by the $\Theta(n)$ term.

Let's pick $n_0=1$.
By choosing a sufficiently large $c$, we can satisfy the condition $T(1)\le c\cdot1^2-d\cdot1$ for any fixed constants $d$ and $T(1)$, so the bound also holds when $n_0\le n<2n_0$.

0 comments on commit 1f93294

Please sign in to comment.