๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐“ก๐“ธ๐“ธ๐“ถ5: ๐’ฆ๐‘œ๐“‡๐‘’๐’ถ ๐’ฐ๐“ƒ๐’พ๐“‹/Discrete mathematics

[์ด์‚ฐ์ˆ˜ํ•™] Chapter 4. Algorithms

1. Introduction

 - ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํŠน์ง•๋“ค์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.

 1) input

 2) output

 3) precision : ์ •ํ™•ํ•˜๊ฒŒ ์„œ์ˆ ๋˜์–ด์•ผ ํ•œ๋‹ค

 4) determinism :  ์ˆ˜ํ–‰์˜๊ฒฐ๊ณผ๋Š” uniqueํ•˜๋‹ค. ๋˜ํ•œ input๊ณผ ์„ ํ–‰๋œ step์— ๋”ฐ๋ผ ๊ฒฐ์ •๋œ๋‹ค.

 5) finiteness : ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ๋๋‚˜์•ผ ํ•œ๋‹ค. (์œ ํ•œ๊ฐœ์˜ instruction์ด ์ˆ˜ํ–‰๋œ ์ดํ›„์—” ๋ฉˆ์ถฐ์•ผ ํ•จ)

 6) correctness : ์•Œ๊ณ ๋ฆฌ์ฆ˜์— ์˜ํ•ด ๋„์ถœ๋œ output์€ ๋งž์•„์•ผ ํ•œ๋‹ค.

 7) generality : ๋ชจ๋“  input์— ๋Œ€ํ•ด ์ ์šฉ๋˜์–ด์•ผ ํ•œ๋‹ค. 

 

2. Examples of Algorithms

 - ํฐ ์ˆ˜ ์ฐพ๊ธฐ ์•Œ๊ณ ๋ฆฌ์ฆ˜, ๋ฌธ์ž์—ด ์ฐพ๊ธฐ ์•Œ๊ณ ๋ฆฌ์ฆ˜, ์‚ฝ์ž… ์ •๋ ฌ ์•Œ๊ณ ๋ฆฌ์ฆ˜

 - Randomized Algorithms (๋ฌด์ž‘์œ„ ์•Œ๊ณ ๋ฆฌ์ฆ˜) : ๋‚œ์ˆ˜๋ฅผ ๋ฐœ์ƒ์‹œ์ผœ ์ง„ํ–‰๊ณผ์ •์„ ๊ฒฐ์ •ํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜

  

3. Analysis of Algorithms

  - Useless program : ๋„ˆ๋ฌด ์˜ค๋žœ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฌ๊ฑฐ๋‚˜ ๋„ˆ๋ฌด ๋งŽ์€ space๋ฅผ ์ฐจ์ง€ํ•ด์„œ๋Š” ์•ˆ๋จ. 

  - Complexity of algorithms : ์‹ค์ œ๋กœ ์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์ˆ˜ํ–‰๋˜๋Š”๋ฐ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„์€ ์ •ํ™•ํžˆ ๊ตฌํ•˜๊ธฐ ํž˜๋“ค๋‹ค. ๋”ฐ๋ผ์„œ ์šฐ๋ฆฌ๋Š” ์ง์ ‘ ์‹œ๊ฐ„์„ ์žฌ๋Š” ๊ฒƒ ๋ณด๋‹ค๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์‹œ๊ฐ„์„ estimate, ์ถ”์ •ํ•  ๊ฒƒ์ด๋‹ค! ์ด ๋•Œ, ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์ˆ˜ํ–‰๋˜๋Š”๋ฐ ํ•„์š”ํ•œ time ํ˜น์€ space๋ฅผ ๋ฐ”๋กœ ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ Complexity๋ผ๊ณ  ํ•œ๋‹ค.

  (ํ”„๋กœ๊ทธ๋žจ์ด ๋Œ์•„๊ฐ€๋Š” ์ปดํ“จํ„ฐ, data๊ฐ€ ํ‘œํ˜„๋˜๋Š” ๋ฐฉ์‹, ํ”„๋กœ๊ทธ๋žจ์ด ๊ธฐ๊ณ„์–ธ์–ด๋กœ ์–ด๋–ป๊ฒŒ ๋ฒˆ์—ญ๋˜์—ˆ๋Š”์ง€, ๋ฌด์Šจ ์–ธ์–ด๊ฐ€ ์“ฐ์˜€๋Š”์ง€ ๋“ฑ์ด Performance์— ์˜ํ–ฅ์„ ๋ฏธ์น˜๋Š” parameter๋“ค์ด๋‹ค)

 

  1) Time complexity

    - Best-case time 

    - Worst-case time

    - Average-case time

 

    - f(n) = O(g(n)) : g(n)์€ f(n)์˜ ์ƒํ•œ์„ , asymptotic upper bound for f (f์˜ ์ƒํ•œ์ ๊ทผ์„ )

      |f(n)| <= C1|g(n)|  (C1์€ ์–‘์˜ ์ƒ์ˆ˜)

 

     ex) 60n^2 + 5n + 1 <= 60n^2 + 5n^2 + 1n^2 = 66n^2

         ์ฆ‰, C1 = 66 -> 60n^2 + 5n + 1 = O(n^2)

 

          2n + 3logn <= 2n + 3n = 5n

          C1 = 5 -> 2n + 3logn = O(n)

 

 - f(n) = Ω(g(n)) : g(n)์€ f(n)์˜ ํ•˜ํ•œ์„ , asymptotic lower bound for f (f์˜ ํ•˜ํ•œ ์ ๊ทผ์„ )

       |f(n)| >= C2|g(n)|  (C1์€ ์–‘์˜ ์ƒ์ˆ˜)

 

   ex) 60n^2 + 5n + 1 >= 60n^2

         ์ฆ‰, C2 = 60 -> 60n^2 + 5n + 1 = Ω(n^2)

 

          2n + 3logn <= 2n 

          C2 = 2-> 2n + 3logn = Ω(n)

 

 

 - f(n) = Θ(g(n)) : g(n)์€ f(n)๊ณผ ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ์ ๊ทผ์„ , asymptotic tight bound for f

 

     ex) 60n^2 + 5n + 1 = O(n^2) ์ด๊ณ  60n^2 + 5n + 1 = Ω(n^2) ์ด๋‹ˆ๊นŒ 

         60n^2 + 5n + 1 = Θ(n^2)

 

        2n + 3logn = O(n) ์ด๊ณ  2n + 3logn = Ω(n) ์ด๋‹ˆ๊นŒ 

        2n + 3logn = Θ(n)

 

์š”๊ฑฐ๋Š” ๊ธฐ๋ณธ์ด๋‹ˆ๊นŒ~

 

 

4. Recursive Algorithms : ์žฌ๊ท€์  ์•Œ๊ณ ๋ฆฌ์ฆ˜, ์ž๊ธฐ ์ž์‹ ์„ ํ˜ธ์ถœํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜

 ex ) n! = n(n-1)! = n(n-1)(n-2)! ... 

      fibonacci sequence : f1 = 1, f2 = 2, fn = fn-1 + fn-2 for n>= 3