Skip to content

Commit

Permalink
apply LaTeX 2
Browse files Browse the repository at this point in the history
  • Loading branch information
oneonlee authored Sep 22, 2023
1 parent 4ffa9ac commit b6b2df7
Showing 1 changed file with 34 additions and 38 deletions.
72 changes: 34 additions & 38 deletions 3. Algorithms/01. Algorithm Complexity Analysis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,88 +79,84 @@
- ๊ทธ ํ•จ์ˆ˜ $g(n)$์€ ์–ด๋–ค 2์ฐจ ํ•จ์ˆ˜ $cn^{2}$ ๋ณด๋‹ค๋Š” ๊ถ๊ทน์ ์œผ๋กœ **์ข‹๋‹ค**๊ณ  (๊ธฐ์šธ๊ธฐ๊ฐ€ **๋‚ฎ๋‹ค**๊ณ ) ๋งํ•  ์ˆ˜ ์žˆ๋‹ค.
- ์–ด๋–ค ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์‹œ๊ฐ„๋ณต์žก๋„๊ฐ€ $O(f(n))$์ด๋ผ๋ฉด
- ์ž…๋ ฅ์˜ ํฌ๊ธฐ $n$์— ๋Œ€ํ•ด์„œ ์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์ˆ˜ํ–‰์‹œ๊ฐ„์€ **์•„๋ฌด๋ฆฌ ๋Šฆ์–ด๋„** $f(n)$์€ ๋œ๋‹ค. ($f(n)$์ด ์ƒํ•œ์ด๋‹ค.)
- ๋‹ค์‹œ ๋งํ•˜๋ฉด, ์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์ˆ˜ํ–‰์‹œ๊ฐ„์€ `f(n)`๋ณด๋‹ค ์ ˆ๋Œ€๋กœ ๋” ๋Š๋ฆด ์ˆ˜๋Š” ์—†๋‹ค๋Š” ๋ง์ด๋‹ค.
- ๋‹ค์‹œ ๋งํ•˜๋ฉด, ์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์ˆ˜ํ–‰์‹œ๊ฐ„์€ $f(n)$๋ณด๋‹ค ์ ˆ๋Œ€๋กœ ๋” ๋Š๋ฆด ์ˆ˜๋Š” ์—†๋‹ค๋Š” ๋ง์ด๋‹ค.
- โ€œ์ตœ์•…์˜ ๊ฒฝ์šฐ ์ด ์ •๋„ ์‹œ๊ฐ„์ด๋ฉด ๋œ๋‹คโ€

#### Tight Upper Bound
- ์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ์–ด๋– ํ•œ ๊ฒฝ์šฐ์—๋„ ์ด ์ƒํ•œ์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค.
- โ€œ๊ธธ์–ด์•ผ $N$` ์‹œ๊ฐ„์ด๋ฉด ๋œ๋‹คโ€๊ฐ€ ์‚ฌ์‹ค์ด๋ผ๋ฉด ๋‹น์—ฐํžˆ โ€œ๊ธธ์–ด์•ผ $N^{2}$ ์‹œ๊ฐ„์ด๋ฉด ๋œ๋‹คโ€๋ผ๊ฑฐ๋‚˜ โ€œ๊ธธ์–ด์•ผ $N^{3}$ ์‹œ๊ฐ„์ด๋ฉด ๋œ๋‹คโ€๋„ ์‚ฌ์‹ค
- โ€œ๊ธธ์–ด์•ผ $N$ ์‹œ๊ฐ„์ด๋ฉด ๋œ๋‹คโ€๊ฐ€ ์‚ฌ์‹ค์ด๋ผ๋ฉด ๋‹น์—ฐํžˆ โ€œ๊ธธ์–ด์•ผ $N^{2}$ ์‹œ๊ฐ„์ด๋ฉด ๋œ๋‹คโ€๋ผ๊ฑฐ๋‚˜ โ€œ๊ธธ์–ด์•ผ $N^{3}$ ์‹œ๊ฐ„์ด๋ฉด ๋œ๋‹คโ€๋„ ์‚ฌ์‹ค
- ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ํŠน์„ฑ์„ ํ‘œํ˜„ํ•˜๋Š” ๋ฐ๋Š” tight upper bound๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•จ.
- Say โ€œ$2n$ is $O(n)$โ€ instead of โ€œ$2n$ is $`O(n^{2})$โ€
- Say " $2n$ is $O(n)$ ", instead of " $2n$ is $O(n^{2})$ "
- Use the simplest expression of the class
- Say โ€œ$3n + 5$ is $O(n)$โ€ instead of โ€œ$3n + 5$ is $O(3n)$โ€
- Say โ€œ $3n + 5$ is $O(n)$ โ€, instead of โ€œ $3n + 5$ is $O(3n)$ โ€

#### Big O ํ‘œ๊ธฐ๋ฒ• : ์ฆ๋ช… โœฉ

1. ๋ถ€๋“ฑ์‹์„ ์„ธ์›Œ๋ผ
- e.g., $n^2 + 10n \geq c \cdot n^{2}$
3. ๋ถ€๋“ฑ์‹์„ ๋งŒ์กฑํ•˜๋Š” $c$, $N$์„ pick!
4. Verify

- eg, `nยฒ+10n โ‰ค cโ‹…nยฒ`

2. ๋ถ€๋“ฑ์‹์„ ๋งŒ์กฑํ•˜๋Š” c, N์„ pick!
3. Verify

##### ์˜ˆ์‹œ

- `nยฒ + 10n` โˆˆ `O(nยฒ)`
- (1) n โ‰ฅ 10์ธ ๋ชจ๋“  ์ •์ˆ˜ n์— ๋Œ€ํ•ด์„œ `nยฒ + 10n โ‰ค 2nยฒ`์ด ์„ฑ๋ฆฝํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ, **c = 2 ์™€ N = 10์„ ์„ ํƒ**ํ•˜๋ฉด, โ€œBig O โ€์˜ ์ •์˜์— ์˜ํ•ด์„œ `nยฒ + 10n โˆˆ O(nยฒ)`์ด๋ผ๊ณ  ๊ฒฐ๋ก  ์ง€์„ ์ˆ˜ ์žˆ๋‹ค.
- (2) n โ‰ฅ 1์ธ ๋ชจ๋“  ์ •์ˆ˜ n์— ๋Œ€ํ•ด์„œ `nยฒ + 10n โ‰ค nยฒ + 10nยฒ = 11nยฒ`์ด ์„ฑ๋ฆฝํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ, **c = 11์™€ N = 1์„ ์„ ํƒ**ํ•˜๋ฉด, โ€œBig Oโ€์˜ ์ •์˜์— ์˜ํ•ด์„œ `nยฒ + 10n โˆˆ O(nยฒ)` ์ด๋ผ๊ณ  ๊ฒฐ๋ก  ์ง€์„ ์ˆ˜ ์žˆ๋‹ค.
##### ์˜ˆ์‹œ
$n^{2} + 10n \in O(n^{2})$
- (1) $n \geq 10$์ธ ๋ชจ๋“  ์ •์ˆ˜ $n$์— ๋Œ€ํ•ด์„œ $n^2 + 10n \leq 2n^{2}$์ด ์„ฑ๋ฆฝํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ, $c = 2$์™€ $N = 10$์„ ์„ ํƒํ•˜๋ฉด, โ€œBig O โ€์˜ ์ •์˜์— ์˜ํ•ด์„œ $n^{2} + 10n \in O(n^{2})$์ด๋ผ๊ณ  ๊ฒฐ๋ก  ์ง€์„ ์ˆ˜ ์žˆ๋‹ค.
- (2) $n \geq 1$์ธ ๋ชจ๋“  ์ •์ˆ˜ $n$์— ๋Œ€ํ•ด์„œ $n^2 + 10n \leq n^2 + 10n^2 = 11n^2$์ด ์„ฑ๋ฆฝํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ, $c = 11$์™€ $N = 1$์„ ์„ ํƒํ•˜๋ฉด, โ€œBig Oโ€์˜ ์ •์˜์— ์˜ํ•ด์„œ $n^2 + 10n \in O(n^{2})$ ์ด๋ผ๊ณ  ๊ฒฐ๋ก  ์ง€์„ ์ˆ˜ ์žˆ๋‹ค.

### Asymptotic Analysis

- **Big-picture** approach
- ์‹คํ–‰์‹œ๊ฐ„์ด โ€œgrows proportionally to `f(n)`โ€ ํ•œ๋‹ค๋Š” ์‚ฌ์‹ค๋งŒ์œผ๋กœ ์ถฉ๋ถ„
- ์‹ค์ œ ์‹คํ–‰ ์‹œ๊ฐ„์€ `c(constant factor)โ‹…f(n)` ์ด ๋จ
- ์–ด๋–ค ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ worst-case๊ฐ€ `g(N) = 60Nยฒ + 5N + `์ด๋ผ๋ฉด
- `g(N) = O(Nยฒ)` : `g(N)`์˜ growth rate๋Š” `Nยฒ`์˜ growth rate๊ณผ ๊ฐ™๋‹ค.
- ์‹คํ–‰์‹œ๊ฐ„์ด โ€œgrows proportionally to $f(n)$โ€ ํ•œ๋‹ค๋Š” ์‚ฌ์‹ค๋งŒ์œผ๋กœ ์ถฉ๋ถ„
- ์‹ค์ œ ์‹คํ–‰ ์‹œ๊ฐ„์€ $c \cdot f(n)$ ์ด ๋จ ($c$: constant factor)
- ์–ด๋–ค ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ worst-case๊ฐ€ $g(N) = 60N^2 + 5N + 3$์ด๋ผ๋ฉด
- $g(N) = O(N^{2})$ : $g(N)$์˜ growth rate๋Š” $N^{2}$์˜ growth rate๊ณผ ๊ฐ™๋‹ค.

### ๋Œ€ํ‘œ์ ์ธ ๋ณต์žก๋„ ์นดํ…Œ๊ณ ๋ฆฌ

#### Polynomial Time

- `O(1)` : constant complexity
- $O(1)$ : constant complexity
- ์ž…๋ ฅ์ž๋ฃŒ์ˆ˜์— ๋ฌด๊ด€
- ํ•ด์‰ฌ
- `O(loglog n)`
- `O(log n)` : logarithmic complexity
- $O( \log \log n)$
- $O( \log n)$ : logarithmic complexity
- divide & conquer
- ์ด์ง„ ๊ฒ€์ƒ‰
- `O(n)` : linear complexity
- $O(n)$ : linear complexity
- scan ๊ฒ€์ƒ‰
- `O(n log n)`
- $O(n \log n)$
- ๋ณ‘ํ•ฉ ์ •๋ ฌ, quick ์ •๋ ฌ...
- `O(n^k)` (k โ‰ฅ 1)
- `O(n2)` : quadratic complexity
- $O(n^{k})$ $(k โ‰ฅ 1)$
- $O(N^{2})$ : quadratic complexity
- ์ด์ค‘ loop, ์‚ฝ์ž…์ •๋ ฌ, ์„ ํƒ์ •๋ ฌ...
- `O(n3)` : cubic complexity
- $O(n^{3})$ : cubic complexity
- ์‚ผ์ค‘ loop, ํ–‰๋ ฌ์˜ ๊ณฑ์…ˆ

#### Exponential Time

- `O(2n)` : exponential complexity
- $O(2^{n})$ : exponential complexity
- Knapsack problem, Fibonacci, Hanoi...

### ฮฉ ํ‘œ๊ธฐ๋ฒ•

- ์ •์˜ : ์ ๊ทผ์  ํ•˜ํ•œ (Asymptotic Tight Lower Bound)

- ์ฃผ์–ด์ง„ ๋ณต์žก๋„ ํ•จ์ˆ˜ `f(n)`์— ๋Œ€ํ•ด์„œ `g(n) โˆˆ ฮฉ(f(n)`์ด๋ฉด ๋‹ค์Œ์„ ๋งŒ์กฑํ•œ๋‹ค.
- n โ‰ฅ N์ธ ๋ชจ๋“  ์ •์ˆ˜ n์— ๋Œ€ํ•ด์„œ `g(n) โ‰ฅ cโ‹…f(n)`์ด ์„ฑ๋ฆฝํ•˜๋Š” ์‹ค์ˆ˜ c>0์™€ ์Œ์ด ์•„๋‹Œ ์ •์ˆ˜ N์ด ์กด์žฌํ•œ๋‹ค.

- `g(n) โˆˆ ฮฉ(f(n))` ์ฝ๋Š” ๋ฐฉ๋ฒ•:
- `g(n)`์€ `f(n)`์˜ ์˜ค๋ฉ”๊ฐ€(omega)
- ์ฃผ์–ด์ง„ ๋ณต์žก๋„ ํ•จ์ˆ˜ $f(n)$์— ๋Œ€ํ•ด์„œ $g(n) \in \Omega(f(n))$์ด๋ฉด ๋‹ค์Œ์„ ๋งŒ์กฑํ•œ๋‹ค.
- $n \geq N$์ธ ๋ชจ๋“  ์ •์ˆ˜ $n$์— ๋Œ€ํ•ด์„œ $g(n) โ‰ฅ c \cdot f(n)$์ด ์„ฑ๋ฆฝํ•˜๋Š” ์‹ค์ˆ˜ $c>0$์™€ ์Œ์ด ์•„๋‹Œ ์ •์ˆ˜ $N$์ด ์กด์žฌํ•œ๋‹ค.
- $g(n) \in \Omega(f(n))$ ์ฝ๋Š” ๋ฐฉ๋ฒ•:
- $g(n)$์€ $f(n)$์˜ ์˜ค๋ฉ”๊ฐ€(omega)

<img width="334" alt="แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2022-04-14 แ„‹แ…ฉแ„’แ…ฎ 10 05 25" src="https://user-images.githubusercontent.com/73745836/163396716-7236fc0f-cca6-489c-a835-f82c3756f2ae.png">

- ์–ด๋–ค ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์‹œ๊ฐ„๋ณต์žก๋„๊ฐ€ `ฮฉ(f(n))`์ด๋ผ๋ฉด,
- ์ž…๋ ฅ์˜ ํฌ๊ธฐ n์— ๋Œ€ํ•ด์„œ ์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์ˆ˜ํ–‰์‹œ๊ฐ„์€ ์•„๋ฌด๋ฆฌ ๋นจ๋ผ๋„ `f(n)`๋ฐ–์— ๋˜์ง€ ์•Š๋Š”๋‹ค. (`f(n)`์ด ํ•˜ํ•œ์ด๋‹ค.)
- ์–ด๋–ค ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์‹œ๊ฐ„๋ณต์žก๋„๊ฐ€ $\Omega (f(n))$์ด๋ผ๋ฉด,
- ์ž…๋ ฅ์˜ ํฌ๊ธฐ $n$์— ๋Œ€ํ•ด์„œ ์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์ˆ˜ํ–‰์‹œ๊ฐ„์€ ์•„๋ฌด๋ฆฌ ๋นจ๋ผ๋„ $f(n)$๋ฐ–์— ๋˜์ง€ ์•Š๋Š”๋‹ค. ($f(n)$์ด ํ•˜ํ•œ์ด๋‹ค.)
- โ€œ์ตœ์†Œํ•œ ์ด๋งŒํ•œ ์‹œ๊ฐ„์€ ๊ฑธ๋ฆฐ๋‹คโ€
- ๋ชจ๋“  ์ •๋ ฌ ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ `ฮฉ(N)`. N๊ฐœ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ •๋ ฌํ•˜๋Š”๋ฐ N๊ฐœ ๋ชจ๋‘๋ฅผ ์ฝ์ง€ ์•Š๊ณ  ์ •๋ ฌ์„ ์™„๋ฃŒํ•  ์ˆ˜๋Š” ์—†๊ธฐ ๋•Œ๋ฌธ. โœฉ
- ๋ชจ๋“  ์ •๋ ฌ ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ $\Omega (N)$. $N$๊ฐœ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ •๋ ฌํ•˜๋Š”๋ฐ $N$๊ฐœ ๋ชจ๋‘๋ฅผ ์ฝ์ง€ ์•Š๊ณ  ์ •๋ ฌ์„ ์™„๋ฃŒํ•  ์ˆ˜๋Š” ์—†๊ธฐ ๋•Œ๋ฌธ. โœฉ

### Summary โœฉ

![IMG_5B36BB702193-1](https://user-images.githubusercontent.com/73745836/163398342-b7255be9-0006-4d7c-aad8-399b6c7553d5.jpeg)

- โ€œThe running time is `O(f(n))`โ€ => Worst case is `O(f(n))`
- โ€œRunning time is `ฮฉ(f(n))`โ€ => Best case is `ฮฉ(f(n))`
- โ€œThe running time is $O(f(n))$โ€ => Worst case is $O(f(n))$
- โ€œRunning time is $\Omega (f(n))$โ€ => Best case is $\Omega (f(n))$

## ์ˆœํ™˜ (recursion)

Expand Down

0 comments on commit b6b2df7

Please sign in to comment.