2020-1ํ•™๊ธฐ, ๋Œ€ํ•™์—์„œ โ€˜์•Œ๊ณ ๋ฆฌ์ฆ˜โ€™ ์ˆ˜์—…์„ ๋“ฃ๊ณ  ๊ณต๋ถ€ํ•œ ๋ฐ”๋ฅผ ์ •๋ฆฌํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค. ์ง€์ ์€ ์–ธ์ œ๋‚˜ ํ™˜์˜์ž…๋‹ˆ๋‹ค :)

8 minute read

2020-1ํ•™๊ธฐ, ๋Œ€ํ•™์—์„œ โ€˜์•Œ๊ณ ๋ฆฌ์ฆ˜โ€™ ์ˆ˜์—…์„ ๋“ฃ๊ณ  ๊ณต๋ถ€ํ•œ ๋ฐ”๋ฅผ ์ •๋ฆฌํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค. ์ง€์ ์€ ์–ธ์ œ๋‚˜ ํ™˜์˜์ž…๋‹ˆ๋‹ค :)


Search Problems

์ง€๊ธˆ๊นŒ์ง€ ์šฐ๋ฆฌ๊ฐ€ ํ’€์—ˆ๋˜ ๋Œ€๋ถ€๋ถ„์˜ ๋ฌธ์ œ๋Š” ์ง€์ˆ˜์ ์œผ๋กœ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ์ผ€์ด์Šค(exponentially possible cases)๋ฅผ ๋ชจ๋‘ ํƒ์ƒ‰ํ•œ๋‹ค๋ฉด ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค. ์ด๋•Œ, ์šฐ๋ฆฌ๊ฐ€ ์ฐพ๋Š” ํ•ด(่งฃ)๋Š” path, tree, matching ๋“ฑ์ด ๋  ์ˆ˜ ์žˆ๋Š”๋ฐ

  • $n$๋ช…์˜ ์†Œ๋…„์„ $n$๋ช…์˜ ์†Œ๋…€์™€ ๋งค์นญ โ†’ $n!$
  • $n$๊ฐœ ๋…ธ๋“œ๊ฐ€ ์žˆ๋Š” ์™„์ „ ๊ทธ๋ž˜ํ”„์˜ spanning tree โ†’ $n^{n-2}$ Caleyโ€™s Formula [link]
  • undirected graph์—์„œ ๋…ธ๋“œ $s$์—์„œ ๋…ธ๋“œ $t$๋กœ ๊ฐ€๋Š” path์˜ ์ˆ˜ โ†’ exponentially many

์œ„์™€ ๊ฐ™์ด ๊ทธ๋ž˜ํ”„๋‚˜ ๋งค์นญ ๋ฌธ์ œ๋ฅผ ํ’€๊ธฐ ์œ„ํ•ด โ€˜๊ฐ€๋Šฅํ•œ ๋ชจ๋“ โ€™ ๊ฒฝ์šฐ๋ฅผ ์‚ดํŽด๋ณธ๋‹ค๋ฉด exponentially manyํ•œ ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๋ชจ๋‘ ํƒ์ƒ‰ํ•ด์•ผ ํ•˜๊ณ , ์ด๊ฒƒ์€ ์‹ค์ „์—์„œ๋Š” ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค. ๊ทธ๋ž˜์„œ ์ง€๊ธˆ๊นŒ์ง€๋Š” exponentially manyํ•œ ๊ฒฝ์šฐ๋ฅผ ๋ชจ๋‘ ์‚ดํŽด๋ณด๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ…Œํฌ๋‹‰์„ ํ™œ์šฉํ•ด polynomially manyํ•œ ๊ฒฝ์šฐ๋งŒ ์‚ดํŽด๋ณด๊ณ  ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ–ˆ๋‹ค!

  • Minimum Spanning Tree
    • Greedy Algorithm: $O(E \log V)$
  • $s-t$ shortest path
    • Dijkstraโ€™s Algorithm: $O((V + E) \log V)$
  • Chain Matrix Multiplication
    • Dynamic Programming: $O(n^3)$
  • Bipartitie Matching
    • Network Flow(Linear Programming): $O(n^3)$

๊ทธ๋Ÿฌ๋‚˜ ์œ„์˜ ์ผ€์ด์Šค๊ฐ€ ์šด์ด ์ข‹์€ ๊ฒƒ์ผ ๋ฟ, ์—ฌ์ „ํžˆ ๋งŽ์€ search problem๋“ค์˜ ๊ฐ€์žฅ ๋น ๋ฅธ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด exponential complexity๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. ์ด๋ฒˆ ์ฑ•ํ„ฐ์—์„œ๋Š” ์ด๋Ÿฐ exponential complexity ๋งŒ์œผ๋กœ ํ•ด๊ฒฐ ๊ฐ€๋Šฅํ•œ ๋ฌธ์ œ๋“ค์— ๋Œ€ํ•ด ์‚ดํŽด๋ณด๊ฒ ๋‹ค ๐Ÿ‘


P and NP

  • ๊ฒฐ์ • ๋ฌธ์ œ(Deterministic Problem)
    • ๋‹ต์ด YES ์•„๋‹ˆ๋ฉด NO๋กœ ๋ฐ˜ํ™˜๋˜๋Š” ๋ฌธ์ œ
    • ex. $a$๋Š” $b$์˜ ๋ฐฐ์ˆ˜์ธ๊ฐ€?
  • ๋‹คํ•ญ ์‹œ๊ฐ„ ์•Œ๊ณ ๋ฆฌ์ฆ˜(polynomial time algorithm)
    • ์‹œ๊ฐ„ ๋ณต์žก๋„๊ฐ€ $O(n^2), O(n^3), โ€ฆ, O(n^k)$์ธ ๊ฒฝ์šฐ๋ฅผ ๋งํ•จ.
  • ์ง€์ˆ˜ ์‹œ๊ฐ„ ์•Œ๊ณ ๋ฆฌ์ฆ˜(exponential time algorithm)
    • ์‹œ๊ฐ„ ๋ณต์žก๋„๊ฐ€ $O(2^n), O(3^n), โ€ฆ O(n^n)$์ธ ๊ฒฝ์šฐ๋ฅผ ๋งํ•จ.

์—ฌ๊ธฐ๊นŒ์ง€๋Š” ์ด๋ฏธ ์•Œ๊ณ  ์žˆ๋Š” ๋‚ด์šฉ์ด๋‹ค.


โ€œ๋ชจ๋“  Search Problem์€ proposed solution $S$๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ๊ทธ๊ฒƒ์ด ์ •๋ง๋กœ solution์ธ์ง€ ์•„๋‹Œ์ง€ poly-time ์•ˆ์— ํŒ๋‹จํ•  ์ˆ˜ ์žˆ๋‹ค.โ€

โ€œFor any search problem, there is an efficient checking algorithm $C$ that takes as input the given instance $I$(amount of input data), as well as the proposed solution $S$, and outputs $true$ if and only if $S$ really is a solution the problem. Moreover the running time of $C(I, S)$ is bounded by a polynomial in $| I |$, the length of the instance.โ€


๊ฐ€์ ค_gazelle๋‹˜์˜ โ€˜P vs NP ์‰ฝ๊ฒŒ ์ดํ•ดํ•˜๊ธฐโ€™ ํฌ์ŠคํŠธ๊ฐ€ ๊ฒฐ์ •์ /๋น„๊ฒฐ์ •์  ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ดํ•ดํ•˜๋Š”๋ฐ ํฐ ๋„์›€์ด ๋˜์—ˆ์Šต๋‹ˆ๋‹ค ๐Ÿ™

  • ๊ฒฐ์ •์  ์•Œ๊ณ ๋ฆฌ์ฆ˜(deterministic algorithm)
    • ๊ณ„์‚ฐ์˜ ๊ฐ ๋‹จ๊ณ„์—์„œ ๋‹จ ํ•œ ๊ฐ€์ง€ ์„ ํƒ์ง€๋งŒ ๊ณ ๋ คํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜
    • DFS๋Š” deterministic์ด๋‹ค. ์™œ๋ƒํ•˜๋ฉด ๋ฐฉ๋ฌธํ•˜๋Š” ์ˆœ์„œ๊ฐ€ ๋ช…ํ™•ํžˆ ์ •ํ•ด์ ธ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค: pre-order, post-order, in-order
    • ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ merge sort๋„ deterministic์ด๋‹ค. Divide-and-Conquer๋กœ ํ’€์ง€๋งŒ ๋ฌธ์ œ๋ฅผ ํ‘ธ๋Š” ์ˆœ์„œ๋Š” ํ•จ์ˆ˜์ฝœ ์ˆœ์„œ๋ฅผ ์ƒ๊ฐํ•˜๋ฉด stack์— ์Œ“์ธ ์ˆœ์„œ๋Œ€๋กœ ์ฒ˜๋ฆฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ˆœ์„œ๊ฐ€ ๋ช…ํ™•ํ•˜๋‹ค.
  • ๋น„๊ฒฐ์ •์  ์•Œ๊ณ ๋ฆฌ์ฆ˜(non-deterministic algorithm)
    • ๊ณ„์‚ฐ์˜ ๊ฐ ๋‹จ๊ณ„์—์„œ ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ์„ ํƒ์ง€๋ฅผ โ€˜๋™์‹œ์—โ€™ ๊ณ ๋ คํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜
    • ๊ฐ€์ ค๋‹˜์˜ ์•„ํ‹ฐํด์—์„œ๋Š” ๋น„๊ฒฐ์ •์  ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์„ ํƒ์ง€๋ฅผ โ€˜๋™์‹œ์—โ€™ ๊ณ ๋ คํ•˜๋Š” ๊ฑธ โ€œ๋ถ„์‹ ์ˆ โ€์ด ๋น„์œ ํ–ˆ์Šต๋‹ˆ๋‹ค!
    • ์ œ๊ฐ€ ๊ณต๋ถ€ํ•œ ์ „๊ณต ์„œ์ ์—์„œ๋„ Non-deterministic Algorithm์€ โ€œA special (and quite unrealistic) sort of algorithm can find and verify the search problem in polynomial time.โ€์œผ๋กœ ๊ธฐ์ˆ ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. โ€œ๋ถ„์‹ ์ˆ โ€์ด๋ผ๋Š” unrealistic ๋ฐฉ๋ฒ•์„ ์“ฐ๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ€์ƒ์—์„œ๋งŒ ์กด์žฌํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด์ฃ .


๋ช‡๊ฐ€์ง€ ์‚ฌ๋ก€๋ฅผ ํ†ตํ•ด Non-deterministic Algorithm์„ ์‚ดํŽด๋ด…์‹œ๋‹ค.

[์›์†Œ ํ•ฉ์ด 0์ด ๋˜๋Š” ๋ถ€๋ถ„์ง‘ํ•ฉ]

$\{ -5, 6, 1, 2, -10, -7, 13 \}$๋ผ๋Š” ์ •์ˆ˜ $n$๊ฐœ์˜ ์ง‘ํ•ฉ์ด ์žˆ์„ ๋•Œ, ์ด ์ง‘ํ•ฉ์˜ ๋ถ€๋ถ„ ์ง‘ํ•ฉ ์ค‘ ์›์†Œ์˜ ํ•ฉ์ด 0์ด ๋˜๋Š” ๋ถ€๋ถ„ ์ง‘ํ•ฉ์ด ์กด์žฌํ•˜๋Š”์ง€ Yes/No๋กœ ๋Œ€๋‹ตํ•˜๋ผ.

length $n$์„ ๊ฐ–๋Š” boolean sequence $(0, 0, โ€ฆ, 1)$๋กœ ๋ถ€๋ถ„์ง‘ํ•ฉ์„ ํ‘œํ˜„ํ•ด ๋ชจ๋“  ๋ถ€๋ถ„์ง‘ํ•ฉ ์กฐํ•ฉ์„ ๋ชจ๋‘ ํ™•์ธํ•ด ์›์†Œ ํ•ฉ์ด 0์ด ๋˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.

์ด ๋ฌธ์ œ๋ฅผ Deterministic Algorithm์œผ๋กœ ํ‘ธ๋ ค๊ณ  ํ•œ๋‹ค๋ฉด, $O(2^n)$ ๋งŒํผ์˜ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฐ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋งˆ๋ฒ•์˜ Non-deterministic Algorithm์œผ๋กœ ํ‘ผ๋‹ค๋ฉด $O(n)$์˜ ์‹œ๊ฐ„์œผ๋กœ ํ’€ ์ˆ˜ ์žˆ๋‹ค. ๋’ค์—์„œ ๋‚˜์˜ค๊ฒ ์ง€๋งŒ, Non-deterministic polynomial solvable ์ด๋ฏ€๋กœ Class $\textbf{NP}$์— ์†ํ•œ๋‹ค!

[์™ธํŒ์› ๋ฌธ์ œ: ๋ชจ๋“  ์ •์ ์„ ๋‹จ ํ•œ๋ฒˆ์”ฉ ๋ฐฉ๋ฌธํ•˜๋Š” ๊ธธ์ด ์กด์žฌํ•˜๋Š”๊ฐ€?]

์ด ๋ฌธ์ œ๋„ polynomial time ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ $n$๊ฐœ ๋…ธ๋“œ์˜ permutation์„ ๋™์‹œ์— ์‚ดํŽด๋ณผ ์ˆ˜ ์žˆ๋Š” ๋งˆ๋ฒ•์˜ Non-deterministic Algorithm์œผ๋กœ ํ‘ผ๋‹ค๋ฉด $O(n)$์˜ ์‹œ๊ฐ„์œผ๋กœ ํ’€ ์ˆ˜ ์žˆ๋‹ค. ๋ฐ”๋กœ ์œ„์˜ [์›์†Œ ํ•ฉ์ด 0์ด ๋˜๋Š” ๋ถ€๋ถ„์ง‘ํ•ฉ] ๋ฌธ์ œ์™€ ๋น„์Šทํ•˜์ง€๋งŒ ์กฐ๊ธˆ ๋‹ค๋ฅธ Non-deterministic Algorithm์ด๋‹ค.

๋งจ ์ฒซ ๋ฐฉ๋ฌธ์ด 1์ธ permutation์„ ์ƒ๊ฐํ•ด๋ณด์ž. ๋‹ค์Œ ๋ฐฉ๋ฌธ์€ $2 \sim n$์ด ๊ฐ€๋Šฅํ•  ๊ฒƒ์ด๋‹ค. ๋ถ„์‹ ์ˆ ์„ ์จ์„œ $(n-1)$ ๊ฐˆ๋ฆผ๊ธธ์„ ๋™์‹œ์— ๋ชจ๋‘ ํ™•์ธํ•œ๋‹ค. ๊ฐ๊ฐ์˜ ๊ฐˆ๋ฆผ๊ธธ์—์„œ $(n-2)$ ๊ฐˆ๋ฆผ๊ธธ์„ ๋˜ ๋™์‹œ์— ๋ชจ๋‘ ํ™•์ธํ•œ๋‹คโ€ฆ

์ด๋ ‡๊ฒŒ ๋™์‹œ์— ๋ฐฉ๋ฌธํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉด, non-deterministic algorithm์œผ๋กœ $O(n)$ ์‹œ๊ฐ„์— ํ•ด๊ฒฐ ๊ฐ€๋Šฅํ•˜๋ฏ€๋กœ Class $\textbf{NP}$์— ์†ํ•œ๋‹ค!



P-and-NP

  • ๋ชจ๋“  Deterministic Algorithm์€ Non-deterministic Algorithm์— ํฌํ•จ๋˜๊ธฐ ๋•Œ๋ฌธ์— Class P๋Š” Class $\textbf{NP}$์— ํฌํ•จ๋œ๋‹ค.
  • Class $\textbf{NP}$ ๋ฌธ์ œ์— ํ•ด๋‹นํ•˜๋”๋ผ๋„ ์ ์ ˆํ•œ Algorithm Technique์„ ์‚ฌ์šฉํ•˜๋ฉด Class $\textbf{P}$์— ์†ํ•˜๋Š” ๋ฌธ์ œ๋“ค๋„ ์žˆ๋‹ค.
    • ์ •๋ ฌ ๋ฌธ์ œ๋Š” permutation์„ ๋ชจ๋‘ ํ™•์ธํ•˜๋Š” Non-deterministic Algorithm์œผ๋กœ ํ’€ ์ˆ˜ ์žˆ๋Š” Class $\textbf{NP}$ ๋ฌธ์ œ์ด์ง€๋งŒ, ์ ์ ˆํ•œ Deterministic ์ •๋ ฌ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด $O(n^2)$ ๋˜๋Š” $O(n \log n)$์œผ๋กœ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” Class $\textbf{P}$ ๋ฌธ์ œ์ด๋‹ค.

๊ณ„์‚ฐ ์ด๋ก ์˜ ๋ฏธํ•ด๊ฒฐ ๋ฌธ์ œ๋กœ โ€œClass $\textbf{P}$์™€ Class $\textbf{NP}$๊ฐ€ ๋™์ผํ•œ ์ง‘ํ•ฉ์ธ์ง€โ€๋ฅผ ํŒ๋‹จํ•˜๋Š” P=NP ๋ฌธ์ œ๊ฐ€ ์žˆ๋‹ค. ๊ฐ€๋Šฅํ•œ ๊ฒฐ๋ก ์œผ๋กœ๋Š” ์•„๋ž˜ ์„ธ ๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.

  • $\textbf{P} = \textbf{NP}$, ์ฆ‰ โ€œ๋ชจ๋“  $\textbf{NP}$ ๋ฌธ์ œ๋Š” $\textbf{P}$๋ฌธ์ œ์ด๋‹ค.โ€๊ฐ€ ์ฐธ์ด๋ผ๋ฉด โ€œ์‰ฝ๊ฒŒ ๊ฒ€์‚ฐํ•  ์ˆ˜ ์žˆ๋Š” ๋ชจ๋“  ๋ฌธ์ œ๋“ค์€ ๋ชจ๋‘ ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋‹ค, ์ฆ‰ ์‰ฝ๊ฒŒ ํ‘ธ๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์กด์žฌํ•œ๋‹ค.โ€
  • $\textbf{P} \neq \textbf{NP}$, ์ฆ‰ โ€œDeterministic Algorithm์œผ๋กœ ํ’€ ์ˆ˜ ์—†๋Š” Class $\textbf{NP}$ ๋ฌธ์ œ๊ฐ€ ์กด์žฌํ•œ๋‹ค.โ€
  • ์ฆ๋ช…ํ•  ์ˆ˜ ์—†๋‹ค.


$\textbf{P}$์™€ $\textbf{NP}$๋ฅผ ์ž˜ ์ดํ•ดํ–ˆ๋‹ค๋ฉด ๋‹ค์Œ์€ $\textbf{NP-complete}$์™€ $\textbf{NP-hard}$๋ฅผ ์ดํ•ดํ•˜๊ณ  ์‹ถ์„ ๊ฒƒ์ด๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ Stayโ€ฆ ์ด ๋‘ ๊ฐœ๋…์„ ์ดํ•ดํ•˜๋ ค๋ฉด ํ™˜์›(reduction)์„ ๋จผ์ € ์ดํ•ดํ•ด์•ผ ํ•˜๋Š”๋ฐ, reduction์„ ์•„๋ฌด ๋ฐ”ํƒ•์—†์ด ๋ฐ”๋กœ ์ดํ•ดํ•˜๋ ค๊ณ  ํ•˜๋ฉด ์–ด๋ ต์ง€๋งŒ ํ•˜๋‹ค. ๊ทธ๋ž˜์„œ ์—ฌ๋Ÿฌ $\textbf{NP}$ class ๋ฌธ์ œ๋“ค์„ ์‚ดํŽด๋ณด๊ณ , ๊ทธ $\textbf{NP}$ class ๋ฌธ์ œ๋“ค์ด ์„œ๋กœ ์–ด๋–ป๊ฒŒ ํ™˜์›(reduction) ๋˜๋Š”์ง€๋ฅผ ์‚ดํŽด๋ณธ ํ›„์— ๋งˆ-์ง€๋ง‰์— $\textbf{NP-complete}$์™€ $\textbf{NP-hard}$์˜ ๊ฐœ๋…์„ ์‚ดํŽด๋ณผ ๊ฒƒ์ด๋‹ค ๐Ÿ‘


References

Categories:

Updated: