Files
2025-10-05 17:47:45 +09:00

1.5 KiB

Review 4-1

  • Hajin Ju, 2024062806

Problem 1

Show that the solution of T(n) = 2T(\lfloor n / 2 \rfloor) + n is O(n \lg n) by the substitution method. (Show the inductive step only.)

Solution 1

  • inductive step
T(n) \leq c n \lg n, \quad (\text{for some}\; c > 0,\, n > n_0)

We can assume the hypothesis(T(n) = O(n\lg n)) holds for all positive int smaller than n. then,

T(\lfloor n / 2 \rfloor) \leq c \lfloor n / 2 \rfloor \lg {\lfloor n / 2 \rfloor} \leq c (n / 2) \lg ( n / 2)\\= c(n/2)(\lg n - \lg 2)

$$\begin{align*} T(n) &= 2T(\lfloor n / 2 \rfloor) + n \leq cn(\lg n - \lg 2) + n\ &=cn\lg n - cn \lg 2 + n\ &=cn \lg - cn + n\ &\leq cn\lg n \end{align*}$$

therefore, T(n) = O(n \lg n)

Problem 2

Use a recursion tree to determine a good asymptotic upper bound on the recurrence T(n) = 3T(\lfloor n / 4 \rfloor) + \theta(n^2).

Solution 2

flowchart TD
    A["$$T(n):\;cn^2$$"] --> B1["$$T(n/4):\;cn^2/16$$"];
    A --> B2["$$T(n/4):\;cn^2/16$$"];
    A --> B3["$$T(n/4):\;cn^2/16$$"];

    subgraph L0[ ]
        A
    end

    subgraph L1[ ]
        B1
        B2
        B3
    end
  • level 0
    • cn^2
  • level 1
    • \frac{3}{16}cn^2
  • level k
    • (\frac{3}{16})^k cn^2
  • level \log_4 n
    • n^{\log_4 3}

therefore, total cost is

$$\begin{align*} T(n) &= \sum^{\log_4 n - 1}{i = 0}(\frac{3}{16})^i cn^2 + \Theta(n^{\log_4 3})\ &< \sum^{\infty}{i = 0}(\frac{3}{16})^i cn^2 + \Theta(n^{\log_4 3})\ &=\frac{16}{13}cn^2 +\Theta(n^{\log_4 3}) = O(n^2) \end{align*}