Asymptotic analysis
도입됨이 수업의 내용
| English | 의미 |
|---|---|
| data structures and algorithms/ˈdeɪtə ˈstrʌktʃəz ænd ˈælɡərɪθəmz/ | 데이터 구조와 알고리즘 |
| Big-O/bɪɡ əʊ/ | 빅-O 표기법 |
| Big-Ω/bɪɡ əʊˈmeɪɡə/ | an asymptotic lower bound: the cost grows at least as fast as this, up to a constant factor |
| Big-Θ | 빅-Θ 표기법 |
| recurrence/rɪˈkʌrəns/ | An equation expressing a quantity, such as running time, using values for smaller inputs. |
| master theorem/ˈmæstə ˈθɪərəm/ | a formula that gives the running time of divide-and-conquer recurrences of the form T(n) = aT(n/b) + f(n) |
| witness/ˈwɪtnəs/ | The constants c and n0 that prove a Big-O claim: the bound holds with factor c for every n from n0 on. |
The yardstick
- Data structures and algorithms 数据结构与算法 means choosing containers and methods by how their cost grows with the input. Big-O 大O记号 is an upper bound on growth, up to a constant. Big-Ω 大Ω记号 is the lower bound, and Big-Θ 大Θ记号 gives the exact rate.
- Drop constants and lower-order terms: $3n^2 + 5n + 7$ is $\Theta(n^2)$. The class matters more than the constant: at $n = 1000$, $n \log_2 n \approx 9\,966$ but $n^2 = 10^6$, about $100$ times more.
The class of 3n^2 + 5n + 7 is —
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Drop constants and lower-order terms; the n squared term grows fastest.
The growth table
- How each class grows (logs rounded):
| $n$ | $\log_2 n$ | $n \log_2 n$ | $n^2$ |
|---|---|---|---|
| 10 | 3 | 33 | 100 |
| 100 | 7 | 664 | $10^4$ |
| 1000 | 10 | 9,966 | $10^6$ |
- And $2^{n}$ is off the scale: $2^{100} \approx 10^{30}$.
- Logs come from halving. An algorithm that halves $n$ at each step has $\log_2 n$ levels: binary search on $16$ items needs at most $4$ probes, because $2^4 = 16$.

Growth classes pull apart
Move n and compare log n, n, n log n and n² operation counts. Even at n = 16 the quadratic is sixteen times the linear, and the gap keeps widening.
Halving the input each step touches —
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Each halving is one step: 16 items resolve in 4 probes because 2 to the 4th is 16.
Order these costs from slowest-growing to fastest-growing.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
지점 $n = 1000$ they read about $10$, $1000$, $9\,966$, $10^6$ 및 $10^{301}$: each class ends up far bigger than the one before it, whatever the constants.
Measure by doubling
- Two loops with $n = 100$: a single loop runs its body $100$ times, and a nested loop runs it $100 \times 100 = 10\,000$ times. Double $n$: the single loop doubles to $200$, the nested loop goes up four times to $40\,000$.
- The ratio on doubling shows the exponent: $2$ means linear, $4$ means quadratic. Count the cost before you believe a claim about it.
A loop that halves i on each pass is $\Theta(\log n)$. Two loops over $n$, one after the other, add up to $\Theta(n)$. A loop inside a halving loop multiplies to $\Theta(n \log n)$, the shape of merge sort.
Doubling n quadruples the running count. The exponent is —
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
The measured ratio on doubling is the exponent: 4 means quadratic.
Recurrences: the cost of recursion
- The cost of a recursive algorithm is a recurrence 递推式. Merge sort splits the input in two and merges in linear time: $T(n) = 2T(n/2) + n$.
- There are $\log_2 n$ levels, each costing $n$, so the total is $\Theta(n \log n)$. From $T(1) = 0$: $T(2) = 2$, $T(4) = 8$, $T(8) = 24 = 8 \log_2 8$.
- The master theorem 主定理 compares the work in the leaves, $n^{\log_b a}$, with the combine work. $T(n) = T(n/2) + 1$ is $\Theta(\log n)$ (binary search). $T(n) = 4T(n/2) + n$ is $\Theta(n^2)$: four half-size calls already cost $n^2$, so the linear combine step does not matter.
With $T(n) = 2T(n/2) + n$ 및 $T(1) = 0$, what is $T(16)$?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
T(2) = 2, T(4) = 8, T(8) = 24, T(16) = 2(24) + 16 = 64 = 16 log2 16.
The recurrence $T(n) = 4T(n/2) + n$ solves to —
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Four calls on half the input: n^(log2 4) = n squared, which outgrows the linear combine step.
Big-O with witnesses
- $f(n) = O(g(n))$ means there are constants $c$ and $n_0$ with $f(n) \le c\,g(n)$ for every $n \ge n_0$. The pair $(c, n_0)$ is called the witness 证据常数.
- For $3n^2 + 5n + 7 \le 4n^2$ we need $n^2 \ge 5n + 7$. This is false at $n = 6$ ($36 < 37$) and true from $n = 7$ ($49 \ge 42$). So $c = 4$, $n_0 = \mathbf{7}$ proves the upper half of $\Theta$.
Smallest whole $n_0$ with $3n^2 + 5n + 7 \le 4n^2$ for all $n \ge n_0$?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
$n^2 - 5n - 7 \ge 0$ first holds at $n = 7$: $49 - 35 - 7 = 7$.
Worked example: the master theorem's three cases
- $T(n) = aT(n/b) + f(n)$: compare $f$ with $n^{\log_b a}$. For $3T(n/2) + n$ the leaves cost $n^{\log_2 3} = n^{1.585}$, which is more than $n$. This is case 1, $\Theta(n^{1.585})$: Karatsuba multiplication.
- For $2T(n/2) + n^2$ the top level costs $n^2$, more than the leaves' $n$. This is case 3, $\Theta(n^2)$. When the two are equal, as in merge sort, case 2 adds a factor $\log n$.
Exponent of $n$ in the solution of $T(n) = 3T(n/2) + n$ (three decimals)?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
$\log_2 3 = 1.585$; the leaves dominate.
$T(n) = 2T(n/2) + n^2$ is $\Theta(n^2 \log n)$.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
The combine work $n^2$ dominates $n^{\log_2 2} = n$: case 3 gives $\Theta(n^2)$.
Marks that slip away
- Keeping the constants. $3n^2 + 5n + 7$ is $\Theta(n^2)$: the $3$ and the lower terms stop mattering as $n$ grows.
- Reading Big-O as the exact cost. $O(n^2)$ is only an upper bound, so a linear algorithm is $O(n^2)$ too. Say $\Theta$ when you mean both bounds.
- Timing one size. One run says nothing about growth. Double $n$ and read the ratio.
Recap
- Big-O bounds above, Big-Ω below, Big-Θ both; drop constants and lower-order terms.
- Halving gives $\log_2 n$; doubling $n$ multiplies the count by $2^k$ for a $\Theta(n^k)$ algorithm.
- $T(n) = 2T(n/2) + n$ is $\Theta(n \log n)$; $T(n) = T(n/2) + 1$ is $\Theta(\log n)$.
어떤 문제가 있었나요? 사이트 팀만 이 내용을 볼 수 있습니다.