Divide and conquer
도입됨
어휘
| English | 의미 |
|---|---|
| merge sort/mɜːdʒ sɔːt/ | merge sort |
| quicksort | quicksort |
English
Split, solve, combine
- Merge sort splits in half, recurses, merges in $\Theta(n)$: $T(n) = 2T(n/2) + \Theta(n) = \Theta(n\log n)$. Quicksort moves the work into the partition — the pivot quality decides everything.

{exercise:uni-cs1002-skeleton}
연습
Binary search recurrence is —
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
One recursive call, constant combine: Theta(log n).
English
Quicksort's three worlds
- Balanced pivots: $\Theta(n\log n)$. Sorted input with first-element pivots: $T(n) = T(n-1) + \Theta(n) = \Theta(n^2)$.
- Course measurements on the 64-element array: merge 310 comparisons, quicksort 356, sorted-input worst 2080. Randomised pivots make the expected count $2n\ln n \approx 1.39\,n\log_2 n$.
{exercise:uni-cs1002-quicksort}
연습
Sorted input with first-element pivots costs quicksort —
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
T(n) = T(n-1) + n: each partition peels one element.
English
Two worked patterns
- Maximum subarray by divide and conquer: left best, right best, or the best crossing the middle — the crossing scan is a full pass, so $\Theta(n\log n)$. On $[-2, 1, -3, 4, -1, 2, 1, -5, 4]$ the answer is 6.
- Binary search is the degenerate case: one recursive call, constant combine, $\Theta(\log n)$ — the pattern survives with one branch.
{exercise:uni-cs1002-subarray}
연습
The maximum subarray of [-2, 1, -3, 4, -1, 2, 1, -5, 4] sums to —
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
The run 4, -1, 2, 1 sums to 6.