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

3 minute read

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

<Euler Path Problem>์€ ์ด์‚ฐ ์ˆ˜ํ•™์˜ ๊ธฐ๋ณธ์ ์ธ ๋ฌธ์ œ๋‹ค. ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์ •๋ง ๊ฐ„๋‹จํ•˜๋‹ˆ ํ•œ๋ฒˆ ์‚ดํŽด๋ณด์ž.


Given a graph, find a path that contains each edge exactly once.

์ฆ‰, ํŽœ์„ ํ•œ๋ฒˆ๋„ ๋–ผ์ง€ ์•Š๊ณ  ์ฃผ์–ด์ง„ ๊ทธ๋ž˜ํ”„๋ฅผ ๊ทธ๋Œ€๋กœ ๊ทธ๋ ค๋‚ผ ์ˆ˜ ์žˆ๋Š๋ƒ์— ๋Œ€ํ•œ ์งˆ๋ฌธ์ด๋‹ค.

๋ฌธ์ œ๋ฅผ ์ œ์‹œํ•œ ์˜ค์ผ๋Ÿฌ๋Š” ๊ทธ๋ž˜ํ”„๊ฐ€ Euler Path๋ฅผ ๊ฐ€์ง€๊ธฐ ์œ„ํ•ด์„  ๋‘ ๊ฐ€์ง€ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•ด์•ผ ํ•œ๋‹ค๊ณ  ์ฃผ์žฅํ–ˆ๋‹ค.

  1. graph is connected (๋‹น์—ฐ)
  2. every verte must have even degree (๋‹จ, start/end vertex๋Š” odd degree ๊ฐ€๋Šฅ)

Euler Path Theorem

Theorem.

A connected undirected graph has an Eulerian cycle iff every vertex has even degree.

Proof. $\implies$

Path๊ฐ€ vertex๋ฅผ ์ง€๋‚˜๋Š” ์ƒํ™ฉ์„ ์ƒ๊ฐํ•ด๋ณด์ž. ๊ทธ๋Ÿฌ๋ฉด, ํ•ด๋‹น vertex์— ๋“ค์–ด๊ฐ€๋Š” ๊ฐ„์„ , ํ•ด๋‹น vertex์—์„œ ๋‚˜๊ฐ€๋Š” ๊ฐ„์„ ์ด ๋ฌด์กฐ๊ฑด ํ•„์š”ํ•˜๋‹ค. ๊ทธ๋ž˜์„œ Path๊ฐ€ vertex๋ฅผ ํ•œ๋ฒˆ ์ง€๋‚  ๋•Œ๋งˆ๋‹ค, ํ•ด๋‹น vertex์˜ 2๊ฐœ์˜ degree๊ฐ€ ๋ณด์žฅ๋œ๋‹ค๋Š” ๊ฒƒ์„ ๋งํ•œ๋‹ค.

Euler cycle์€ ๊ทธ๋ž˜ํ”„์˜ ๋ชจ๋“  vertex๋ฅผ ์ง€๋‚˜๊ฒŒ ๋œ๋‹ค. ๊ทธ๋ž˜์„œ Euler cycle์ด ์ง€๋‚˜๋Š” ๋ชจ๋“  ์ •์ ์€ path๊ฐ€ vertex๋ฅผ ๋ฐฉ๋ฌธํ•˜๋Š” ํšŸ์ˆ˜์˜ 2๋ฐฐ ๋งŒํผ์˜ ์ •์ ์„ ๋ฐ˜๋“œ์‹œ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. ์ด๋•Œ, Euler cycle์€ graph์˜ ๋ชจ๋“  ๊ฐ„์„  ์ฆ‰, vertex์˜ ๋ชจ๋“  edge๋ฅผ ์ง€๋‚˜๋ฏ€๋กœ path๊ฐ€ vertex๋ฅผ ๋ฐฉ๋ฌธํ•˜๋ฉฐ ํ›‘๊ณ  ๋‚จ์€ edge๋Š” ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค.

๋”ฐ๋ผ์„œ, Euler cycle์„ ๊ฐ–๋Š” graph์˜ vertex๋Š” ๋ชจ๋‘ even degree๋ฅผ ๊ฐ–๋Š”๋‹ค. $\blacksquare$

Proof. $\impliedby$

  1. ํ•œ vertex์—์„œ ์‹œ์ž‘ํ•ด ์ธ์ ‘ํ•œ vertex ์ค‘ ํ•˜๋‚˜๋ฅผ ๋ฐฉ๋ฌธํ•œ๋‹ค. ์ด ๊ณผ์ •์„ ์œ ํ•œ๋ฒˆ ๋ฐ˜๋ณตํ•˜๋ฉด, ์–ธ์  ๊ฐ€ ์ถœ๋ฐœํ–ˆ๋˜ vertex๋กœ ๋Œ์•„์˜ค๊ฒŒ ๋œ๋‹ค! (even degree graph์˜ ์„ฑ์งˆ์— ์˜ํ•ด cycle์ด ๋ฐ˜๋“œ์‹œ ์กด์žฌํ•จ)

  2. ๋งŒ์•ฝ ์šฐ๋ฆฌ๊ฐ€ ์‹œ์ž‘ vertex๋กœ ๋Œ์•„์™”์„ ๋•Œ graph์˜ ๋ชจ๋“  ์ •์ ์„ ๋ฐฉ๋ฌธํ•œ ๊ฒƒ์ด๋ผ๋ฉด, ๊ทธ cycle์ด ๋ฐ”๋กœ Euler cycle์ด๋‹ค!
  3. ๋งŒ์•ฝ ์•„์ง ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์€ edge๊ฐ€ ๋‚จ์•˜๋‹ค๋ฉด, ์ง์ „์˜ cycle์„ ๊ธฐ์กด ๊ทธ๋ž˜ํ”„์—์„œ ์ง€์›Œ์ค€๋‹ค. cycle์„ ์ง€์› ๊ธฐ ๋•Œ๋ฌธ์— ๊ทธ๋ž˜ํ”„์˜ ๊ฐ„์„ ๋„ ์ง์ˆ˜๊ฐœ ๋งŒํผ ์‚ฌ๋ผ์ง„๋‹ค.
  4. ์œ„์˜ ๊ณผ์ •์„ ๋ชจ๋“  ์ •์ ์„ ๋ฐฉ๋ฌธํ•  ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณตํ•œ๋‹ค.

$\blacksquare$


์‹œ๊ฐ„ ๋ณต์žก๋„

์ฃผ์–ด์ง„ ๊ทธ๋ž˜ํ”„๊ฐ€ Euler cycle์ธ์ง€๋Š” $O(V)$ ๋งŒ์— ํŒ๋‹จํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‹จ์ˆœํžˆ ๊ฐ ์ •์ ์˜ degree ๊ฐฏ์ˆ˜๊ฐ€ ๋ชจ๋‘ ์ง์ˆ˜ ๊ฐœ์ธ์ง€๋งŒ ์„ธ๋ฉด ๋˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

์ฃผ์–ด์ง„ ๊ทธ๋ž˜ํ”„์—์„œ Euler cycle์„ ์ฐพ๋Š” ๊ฒƒ ์—ญ์‹œ ๋งˆ์ฐฌ๊ฐ€์ง€๋‹ค. ์ ์ • ํ•˜๋‚˜๋ฅผ ์ •ํ•ด DFS/BFS๋กœ ์ •์ ์„ ๋ฐฉ๋ฌธํ•˜๋ฉฐ cycle์„ ์ƒ์„ฑํ•˜๋ฉด ๋œ๋‹ค. cycle์ด ์ƒ์„ฑ๋˜๋ฉด ํ•ด๋‹น cycle์„ ๊ทธ๋ž˜ํ”„์—์„œ ์ง€์›Œ์ค€๋‹ค. ์ด ๊ณผ์ •์„ ๋ฐ˜๋ณตํ•ด ๋ฐฉ๋ฌธํ•œ ์ •์ ์˜ ์ˆœ์„œ๊ฐ€ ๋ฐ”๋กœ Euler Cycle์ด๋‹ค. ๊ฐ ์ •์ ์„ ํ•œ๋ฒˆ์”ฉ ๋ฐฉ๋ฌธํ•˜๊ฒŒ ๋˜๊ธฐ ๋•Œ๋ฌธ์— $O(V)$์˜ ์‹œ๊ฐ„์— ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.


๋งบ์Œ๋ง

<Euler Path Problem>๊ณผ ๋น„์Šทํ•˜๊ฒŒ <Hamilton Path Problem>๋„ ์กด์žฌํ•œ๋‹ค. ์ด ๊ฒฝ์šฐ๋Š” ๋ชจ๋“  ์ •์ ์„ ํ•œ๋ฒˆ์”ฉ๋งŒ ๋ฐฉ๋ฌธํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์กด์žฌํ•˜๋Š”์ง€ ํŒ๋ณ„ํ•ด์•ผ ํ•œ๋‹ค. <Euler Path Problem>๊ณผ ๋‹ฌ๋ฆฌ poly-time์œผ๋กœ ํ•ด๊ฒฐ๋˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค. ๋‹ค์Œ ํฌ์ŠคํŠธ์—์„œ ์ด ๋ฌธ์ œ์— ๋Œ€ํ•ด ์‚ดํŽด๋ณด๊ฒ ๋‹ค.

๐Ÿ‘‰ Hamilton Cycle Problem

Categories:

Updated: