5.13

From The Algorithm Design Manual Solution Wiki
Jump to navigation Jump to search

Using the Master/iteration methods:
1. Algorithm [math]A[/math]:   T(n)=5T(n/2)+Θ(n). Here a=5, b=2, f(n)=n, so nlog₂5≈n2.322 dominates.   T(n)=Θ(nlog₂5) = O(n2.32).

2. Algorithm [math]B[/math]:   T(n)=2T(n-1)+Θ(1). Unfolding gives T(n)=2·2···2 = 2n, hence   T(n)=Θ(2n) = O(2n).

3. Algorithm [math]C[/math]:   T(n)=9T(n/3)+Θ(n²). Now a=9, b=3, nlog₃9=n², so f(n)=Θ(n²) matches case 2 of the Master Theorem.   T(n)=Θ(n² log n) = O(n² log n).

Asymptotically O(n² log n) < O(n2.32) << O(2n), so for large problem sizes the best choice is Algorithm [math]C[/math].


Back to Chapter 5