Skip to content

Commit

Permalink
#168 4-4i
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtask committed Dec 5, 2024
1 parent ebdae5e commit 82ca6bd
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
6 changes: 5 additions & 1 deletion chapter4/problems/4/g.tex
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Let $n_0>0$ be the implicit threshold constant, and let $d>0$ be another constant such that $T(n)\le d$ for all $n<n_0$.
We'll prove by induction that $H_n-H_{n_0}<T(n)<H_n+d$ for all $n>0$.
We'll prove by induction that
\[
H_n-H_{n_0} < T(n) < H_n+d
\]
for all $n>0$.

First, let $0<n<n_0$.
Since the harmonic series strictly increases and consists of positive terms, $H_n-H_{n_0}<0\le T(n)\le d<H_n+d$.
Expand Down
61 changes: 60 additions & 1 deletion chapter4/problems/4/i.tex
Original file line number Diff line number Diff line change
@@ -1 +1,60 @@
\workinprogress % TODO
Let $n_0>0$ be the implicit threshold constant, and let $d>0$ be another constant such that $T(n)\le d$ for all $n<n_0$.
We'll use mathematical induction to show that
\[
\sum_{i=\lfloor n_0/2\rfloor+1}^{\lceil n/2\rceil}\frac{1}{1+\lg i} \le T(n) \le d+\sum_{i=1}^{\lfloor n/2\rfloor}\frac{1}{1+\lg i}
\]
for all $n>0$.

Let $0<n<n_0$.
Because $\lceil n/2\rceil<\lfloor n_0/2\rfloor+1$,
\begin{align*}
T(n) &\ge 0 \\
&= \sum_{i=\lfloor n_0/2\rfloor+1}^{\lceil n/2\rceil}\frac{1}{1+\lg i}.
\end{align*}
Also,
\begin{align*}
T(n) &\le d \\
&\le d+\sum_{i=1}^{\lfloor n/2\rfloor}\frac{1}{1+\lg i},
\end{align*}
so the base case holds.

For the inductive case let $n\ge n_0$ and suppose that
\[
\sum_{i=\lfloor n_0/2\rfloor+1}^{\lceil(n-2)/2\rceil}\frac{1}{1+\lg i} \le T(n-2) \le d+\sum_{i=1}^{\lfloor(n-2)/2\rfloor}\frac{1}{1+\lg i}.
\]
By the inductive hypothesis, we have
\begin{align*}
T(n) &= T(n-2)+\frac{1}{\lg n} \\
&\ge \sum_{i=\lfloor n_0/2\rfloor+1}^{\lceil(n-2)/2\rceil}\frac{1}{1+\lg i}+\frac{1}{\lg n} \\[1mm]
&= \sum_{i=\lfloor n_0/2\rfloor+1}^{\lceil n/2-1\rceil}\frac{1}{1+\lg i}+\frac{1}{\lg(2n/2)} \\[1mm]
&\ge \sum_{i=\lfloor n_0/2\rfloor+1}^{\lceil n/2\rceil-1}\frac{1}{1+\lg i}+\frac{1}{1+\lg\lceil n/2\rceil} \\[1mm]
&= \sum_{i=\lfloor n_0/2\rfloor+1}^{\lceil n/2\rceil}\frac{1}{1+\lg i}.
\end{align*}
Similarly,
\begin{align*}
T(n) &= T(n-2)+\frac{1}{\lg n} \\
&\le d+\sum_{i=1}^{\lfloor(n-2)/2\rfloor}\frac{1}{1+\lg i}+\frac{1}{\lg n} \\[1mm]
&= d+\sum_{i=1}^{\lfloor n/2-1\rfloor}\frac{1}{1+\lg i}+\frac{1}{\lg(2n/2)} \\[1mm]
&\le d+\sum_{i=1}^{\lfloor n/2\rfloor-1}\frac{1}{1+\lg i}+\frac{1}{1+\lg\lfloor n/2\rfloor} \\[1mm]
&= d+\sum_{i=1}^{\lfloor n/2\rfloor}\frac{1}{1+\lg i}.
\end{align*}

For the proven bounds for $T(n)$, it follows that
\begin{align*}
T(n) &\ge \sum_{i=\lfloor n_0/2\rfloor+1}^{\lceil n/2\rceil}\frac{1}{1+\lg i} \\[1mm]
&\ge \sum_{i=\lfloor n_0/2\rfloor+1}^{\lceil n/2\rceil}\frac{1}{1+\lg((n+1)/2)} \\[1mm]
&= \sum_{i=\lfloor n_0/2\rfloor+1}^{\lceil n/2\rceil}\frac{1}{\lg(n+1)} \\[1mm]
&= \frac{\lceil n/2\rceil-\lfloor n_0/2\rfloor}{\lg(n+1)} \\
&= \Omega(n/\lg n)
\end{align*}
and
\begin{align*}
T(n) &\le d+\sum_{i=1}^{\lfloor n/2\rfloor}\frac{1}{1+\lg i} \\
&\le d+\frac{1}{1+\lg1}+\sum_{i=2}^{\lfloor n/2\rfloor}\frac{1}{\lg i} \\
&= d+1+\sum_{i=2}^{\left\lceil\sqrt{n}\right\rceil-1}\frac{1}{\lg i}+\sum_{i=\left\lceil\sqrt{n}\right\rceil}^{\lfloor n/2\rfloor}\frac{1}{\lg i} \\
&\le d+1+\sum_{i=2}^{\left\lceil\sqrt{n}\right\rceil-1}\frac{1}{\lg2}+\sum_{i=\left\lceil\sqrt{n}\right\rceil}^{\lfloor n/2\rfloor}\frac{1}{\lg\sqrt{n}} \\
&= d+1+\left(\left\lceil\sqrt{n}\right\rceil-2\right)+\left(\lfloor n/2\rfloor-\left\lceil\sqrt{n}\right\rceil+1\right)\frac{2}{\lg n} \\
&< d+\left\lceil\sqrt{n}\right\rceil+\frac{n}{\lg n} \\
&= O(n/\lg n).
\end{align*}
Hence, $T(n)=\Theta(n/\lg n)$.

0 comments on commit 82ca6bd

Please sign in to comment.