Skip to content

Commit

Permalink
Update 4.4.md
Browse files Browse the repository at this point in the history
Corrections made to exercise 4.4-4 solution.
  • Loading branch information
aschroede authored and Peng-Yu Chen committed Jun 11, 2022
1 parent c9ecb34 commit 111a7b7
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions docs/Chap04/4.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,35 @@
- The subproblem size for a node at depth $i$ is $n - i$.

Thus, the tree has $n$ levels and $2^{n - 1}$ leaves.
Thus, the tree has $n + 1$ levels ($i = 0, 1, 2, \dots, n$) and $2^n$ leaves.

The total cost over all nodes at depth $i$, for $i = 0, 1, 2, \ldots, n - 1$, is $2^i$.

The $n$-th level has $2^n$ leaves each with cost $\Theta(1)$, so the total cost of the $n$-th level is $\Theta(2^n)$.

Adding the costs of all the levels of the recursion tree we get the following:

$$
\begin{aligned}
T(n) & = \sum_{i = 0}^{n - 1} 2^i \\\\
& = \frac{2^n - 1}{2 - 1} \\\\
& = 2^n - 1 \\\\
T(n) & = \sum_{i = 0}^{n - 1} 2^i + \Theta(2^n)\\\\
& = \frac{2^n - 1}{2 - 1} + \Theta(2^n)\\\\
& = 2^n - 1 + \Theta(2^n)\\\\
& = \Theta(2^n).
\end{aligned}
$$

- We guess $T(n) \le c2^n + n$,
- We guess $T(n) \le c2^n - d$,

$$
\begin{aligned}
T(n) & \le 2 \cdot c2^{n - 1} + (n - 1) + 1 \\\\
& = c2^n + n \\\\
& = O(2^n).
T(n) & \le 2(c2^{n - 1} - d) + 1 \\\\
& = c2^n - 2d + 1 \\\\
& \le c2^n - d
\end{aligned}
$$

Where the last step holds for $d \ge 1$. Thus $T(n) = O(n^2)$.

## 4.4-5

> Use a recursion tree to determine a good asymptotic upper bound on the recurrence $T(n) = T(n - 1) + T(n / 2) + n$. Use the substitution method to verify your answer.
Expand Down

0 comments on commit 111a7b7

Please sign in to comment.