4.3 The substitution method for solving recurrences
4.3-1
Show that the solution of \(T(n) = T(n - 1) + n\) is \(O(n^2)\).
We guess \(T(n) \le cn^2\),
where the last step holds for \(c > \frac{1}{2}\).
4.3-2
Show that the solution of \(T(n) = T(\lceil n / 2 \rceil) + 1\) is \(O(\lg n)\).
We guess \(T(n) \le c\lg(n - a)\),
4.3-3
We saw that the solution of \(T(n) = 2T(\lfloor n / 2 \rfloor) + n\) is \(O(n\lg n)\). Show that the solution of this recurrence is also \(\Omega(n\lg n)\). Conclude that the solution is \(\Theta(n\lg n)\).
First, we guess \(T(n) \le cn\lg n\),
where the last step holds for \(c \ge 1\).
Next, we guess \(T(n) \ge c(n + a)\lg(n + a)\),
4.3-4
Show that by making a different inductive hyptohesis, we can overcome the difficulty with the boundary condition \(T(1) = 1\) for recurrence \(\text{(4.19)}\) without adjusting the boundary conditions for the inductive proof.
We guess \(T(n) \le n\lg n + n\),
where the last step holds for \(c \ge 1\).
This time, the boundary condition is
4.3-5
Show that \(\Theta(n\lg n)\) is the solution to the "exact" recurrence \(\text{(4.3)}\) for merge sort.
The recurrence is
\[T(n) = T(\lceil n / 2 \rceil) + T(\lfloor n / 2 \rfloor) + \Theta(n) \tag{4.3}\]
To show \(\Theta\) bound, separately show \(O\) and \(\Omega\) bounds.
- For \(O(n\lg n)\), we guess \(T(n) \le c(n - 2)\lg(n - 2) - 2c\),
$$ \begin{aligned} T(n) & \le c(\lceil n / 2 \rceil -2 )\lg(\lceil n / 2 \rceil - 2) + c(\lfloor n / 2 \rfloor - 2)\lg(\lfloor n / 2 \rfloor - 2) + dn \\ & \le c(n / 2 + 1 - 2)\lg(n / 2 + 1 - 2) - 2c + c(n / 2 - 2)\lg(n / 2 - 2) - 2c + dn \\ & \le c(n / 2 - 1 )\lg(n / 2 - 1) + c(n / 2 - 1)\lg(n / 2 - 1) + dn \\ & = c\frac{n - 2}{2}\lg\frac{n - 2}{2} + c\frac{n - 2}{2}\lg\frac{n - 2}{2} - 4c + dn \\ & = c(n - 2)\lg\frac{n - 2}{2} - 4c + dn \\ & = c(n - 2)\lg(n - 2) - c(n - 2) - 4c + dn \\ & = c(n - 2)\lg(n - 2) + (d - c)n + 2c - 4c \\ & \le c(n - 2)\lg(n - 2) - 2c, \end{aligned} $$
where the last step holds for \(c > d\).
- For \(\Omega(n\lg n)\), we guess \(T(n) \ge c(n + 2)\lg (n + 2) + 2c\),
$$ \begin{aligned} T(n) & \ge c(\lceil n / 2 \rceil +2 )\lg(\lceil n / 2 \rceil + 2) + c(\lfloor n / 2 \rfloor + 2)\lg(\lfloor n / 2 \rfloor + 2) + dn \\ & \ge c(n / 2 + 2)\lg(n / 2 + 2) + 2c + c(n / 2 - 1 + 2)\lg(n / 2 - 1 + 2) + 2c + dn \\ & \ge c(n / 2 + 1)\lg(n / 2 + 1) + c(n / 2 + 1)\lg(n / 2 + 1) + 4c + dn \\ & \ge c\frac{n + 2}{2}\lg\frac{n + 2}{2} + c\frac{n + 2}{2}\lg\frac{n + 2}{2} + 4c + dn \\ & = c(n + 2)\lg\frac{n + 2}{2} + 4c + dn \\ & = c(n + 2)\lg(n + 2) - c(n + 2) + 4c + dn \\ & = c(n + 2)\lg(n + 2) + (d - c)n - 2c + 4c \\ & \ge c(n + 2)\lg(n + 2) + 2c, \end{aligned} $$
where the last step holds for \(d > c\).
4.3-6
Show that the solution to \(T(n) = 2T(\lfloor n / 2 \rfloor + 17) + n\) is \(O(n\lg n)\).
We guess \(T(n) \le c(n - a)\lg(n - a)\),
4.3-7
Using the master method in Section 4.5, you can show that the solution to the recurrence \(T(n) = 4T(n / 3) + n\) is \(T(n) = \Theta(n^{\log_3 4})\). Show that a substitution proof with the assumption \(T(n) \le cn^{\log_3 4}\) fails. Then show how to subtract off a lower-order term to make the substitution proof work.
We guess \(T(n) \le cn^{\log_3 4}\) first,
We stuck here.
We guess \(T(n) \le cn^{\log_3 4} - dn\) again,
where the last step holds for \(d \ge 3\).
4.3-8
Using the master method in Section 4.5, you can show that the solution to the recurrence \(T(n) = 4T(n / 2) + n\) is \(T(n) = \Theta(n^2)\). Show that a substitution proof with the assumption \(T(n) \le cn^2\) fails. Then show how to subtract off a lower-order term to make the substitution proof work.
First, let's try the guess \(T(n) \le cn^2\). Then, we have
We can't proceed any further from the inequality above to conclude \(T(n) \le cn^2\).
Alternatively, let us try the guess
which subtracts off a lower-order term. Now we have
where the last step holds for \(c \ge 1 / 2\).
4.3-9
Solve the recurrence \(T(n) = 3T(\sqrt n) + \log n\) by making a change of variables. Your solution should be asymptotically tight. Do not worry about whether values are integral.
First,
Now we guess \(S(m) \le cm^{\lg 3} + dm\),
Then we guess \(S(m) \ge cm^{\lg 3} + dm\),
Thus,
本页面的全部内容在 小熊老师 - 莆田青少年编程俱乐部 0594codes.cn 协议之条款下提供,附加条款亦可能应用