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

๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ137

14-3๊ฐ•. ๊ทธ๋ž˜ํ”„์—์„œ์˜ DFS DFS(Depth-First Search) ๊นŠ์ด ์šฐ์„  ํƒ์ƒ‰ level order traversal (BFS) inorder traversal (DFS) pre-order traversal (DFS) post-order traversal (DFS) 1. ์ถœ๋ฐœ์  s์—์„œ ์‹œ์ž‘ํ•œ๋‹ค. 2. ํ˜„์žฌ ๋…ธ๋“œ๋ฅผ visited๋กœ markํ•˜๊ณ , ์ธ์ ‘ํ•œ ๋…ธ๋“œ๋“ค ์ค‘ unvisited ๋…ธ๋“œ๊ฐ€ ์กด์žฌํ•˜๋ฉด ๊ทธ ๋…ธ๋“œ๋กœ ๊ฐ„๋‹ค. 3. 2๋ฒˆ์„ ๊ณ„์† ๋ฐ˜๋ณตํ•œ๋‹ค. 4. ๋งŒ์•ฝ unvisited์ธ ์ด์›ƒ๋…ธ๋“œ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๋™์•ˆ ๊ณ„์†ํ•ด์„œ ์ง์ „ ๋…ธ๋“œ๋กœ ๋˜๋Œ์•„ ๊ฐ„๋‹ค. 5. ๋‹ค์‹œ 2๋ฒˆ์„ ๋ฐ˜๋ณตํ•œ๋‹ค. 6. ์‹œ์ž‘๋…ธ๋“œ s๋กœ ๋Œ์•„์˜ค๊ณ , ๋”์ด์ƒ ๊ฐˆ ๊ณณ์ด ์—†์œผ๋ฉด ์ข…๋ฃŒํ•œ๋‹ค. ์ด ๊ทธ๋ž˜ํ”„์—์„œ๋Š” 1-3-7-8-7-3-5-2-4-2-5-6 ์ˆœ์„œ๋กœ ๊ฐ„๋‹ค.. (ํ•˜์ง€๋งŒ ์ˆœ์„œ๋Š” ๋ฐ”๋€” ์ˆ˜.. 2020. 12. 6.
14-1๊ฐ•. ๊ทธ๋ž˜ํ”„(Graph) ๊ฐœ๋…๊ณผ ํ‘œํ˜„ (๋ฌด๋ฐฉํ–ฅ) ๊ทธ๋ž˜ํ”„. G = (V, E) - V : ๋…ธ๋“œ(node) ํ˜น์€ ์ •์ (vertex) - E : ๋…ธ๋“œ ์Œ์„ ์—ฐ๊ฒฐํ•˜๋Š” ์—์ง€(edge) ํ˜น์€ ๋งํฌ(link) - ๊ฐœ์ฒด(object)๋“ค ๊ฐ„์˜ ์ด์ง„๊ด€๊ณ„๋ฅผ ํ‘œํ˜„ - n = |V|, m = |E| ๋ฐฉํ–ฅ๊ทธ๋ž˜ํ”„(Directetd Graph). G=(V, E) - ์—์ง€(u, v)๋Š” u๋กœ๋ถ€ํ„ฐ v๋กœ์˜ ๋ฐฉํ–ฅ์„ ๊ฐ€์ง ๊ฐ€์ค‘์น˜ (weighted) ๊ทธ๋ž˜ํ”„ - ์—์ง€๋งˆ๋‹ค ๊ฐ€์ค‘์น˜(weight)๊ฐ€ ์ง€์ • ๊ทธ๋ž˜ํ”„์˜ ํ‘œํ˜„ - ์ธ์ ‘ํ–‰๋ ฌ (adjacency matrix) - ์ธ์ ‘๋ฆฌ์ŠคํŠธ (adjacency list) ์œ„์˜ ๊ทธ๋ฆผ์—์„œ m์€ ์—ฃ์ง€์˜ ๊ฐฏ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค.. n(:๋…ธ๋“œ์˜ ๊ฐฏ์ˆ˜) + 2m(:๋…ธ๋“œ ๊ฐฏ์ˆ˜) ์ด์–ด์„œ ์ €์žฅ๊ณต๊ฐ„์€ O(n+m)์ด๋‹ค. ๋ฐฉํ–ฅ๊ทธ๋ž˜ํ”„๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ• ๊ฐ€์ค‘์น˜ ๊ทธ๋ž˜ํ”„์˜ ์ธ์ ‘ํ–‰๋ ฌ ํ‘œํ˜„ .. 2020. 12. 1.
13-3. ํ•ด์Š 3 ์ข‹์€ ํ•ด์‰ฌ ํ•จ์ˆ˜๋ž€? - ํ˜„์‹ค์—์„œ๋Š” ํ‚ค๋“ค์ด ๋žœ๋คํ•˜์ง€ ์•Š์Œ - ๋งŒ์•ฝ ํ‚ค๋“ค์˜ ํ†ต๊ณ„์  ๋ถ„ํฌ์— ๋Œ€ํ•ด ์•Œ๊ณ  ์žˆ๋‹ค๋ฉด ์ด๋ฅผ ์ด์šฉํ•ด์„œ ํ•ด์‰ฌ ํ•จ์ˆ˜๋ฅผ ๊ณ ์•ˆํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€๋Šฅํ•˜๊ฒ ์ง€๋งŒ ํ˜„์‹ค์ ์œผ๋กœ ์–ด๋ ค์›€ - ํ‚ค๋“ค์ด ์–ด๋–ค ํŠน์ •ํ•œ (๊ฐ€์‹œ์ ์ธ) ํŒจํ„ด์„ ๊ฐ€์ง€๋”๋ผ๋„ ํ•ด์‰ฌํ•จ์ˆ˜๊ฐ’์ด ๋ถˆ๊ทœ์น™์ ์ด ๋˜๋„๋ก ํ•˜๋Š” ๊ฒŒ ๋ฐ”๋žŒ์ง - ํ•ด์‰ฌํ•จ์ˆ˜ ๊ฐ’์ด ํ‚ค์˜ ํŠน์ • ๋ถ€๋ถ„์— ์˜ํ•ด์„œ๋งŒ ๊ฒฐ์ •๋˜์ง€ ์•Š์•„์•ผ.. Division ๊ธฐ๋ฒ• - h(k) = k mod m - ์˜ˆ : m = 20 and k = 91 -> h(k) = 11 - ์žฅ์  : ํ•œ ๋ฒˆ์˜ mod ์—ฐ์‚ฐ์œผ๋กœ ๊ณ„์‚ฐ. ๋”ฐ๋ผ์„œ ๋น ๋ฆ„. - ๋‹จ์  : ์–ด๋–ค m๊ฐ’์— ๋Œ€ํ•ด์„œ๋Š” ํ•ด์‰ฌ ํ•จ์ˆ˜๊ฐ’์ด ํ‚ค๊ฐ’์˜ ํŠน์ • ๋ถ€๋ถ„์— ์˜ํ•ด์„œ ๊ฒฐ์ •๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Œ. ๊ฐ€๋ น m = 2^p์ด๋ฉด ํ‚ค์˜ ํ•˜์œ„ p๋น„ํŠธ๊ฐ€ ํ•ด์‰ฌํ•จ์ˆ˜ ๊ฐ’์ด ๋จ. Multiplication ๊ธฐ๋ฒ• -.. 2020. 11. 29.
13-1๊ฐ•. ํ•ด์Š(Hashing) 1 SUHA(Simple Uniform Hashing Assumption) - ๊ฐ๊ฐ์˜ ํ‚ค๊ฐ€ ๋ชจ๋“  ์Šฌ๋กฏ๋“ค์— ๊ท ๋“ฑํ•œ ํ™•๋ฅ ๋กœ() ๋…๋ฆฝ์ ์œผ๋กœ(independently) ํ•ด์Š๋œ๋‹ค๋Š” ๊ฐ€์ • => ์‚ฌ์‹ค ํ˜„์‹ค์ ์ด์ง€ ์•Š๋‹ค. - ์„ฑ๋Šฅ๋ถ„์„์„ ์œ„ํ•ด์„œ ์ฃผ๋กœ ํ•˜๋Š” ๊ฐ€์ •์ผ ๋ฟ - hash ํ•จ์ˆ˜๋Š” deterministicํ•˜๋ฏ€๋กœ ํ˜„์‹ค์—์„œ๋Š” ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค - Load factor alpha = n/m: - n : ํ…Œ์ด๋ธ”์— ์ €์žฅ๋  ํ‚ค์˜ ๊ฐฏ์ˆ˜ - m : ํ•ด์‰ฌํ…Œ์ด๋ธ”์˜ ํฌ๊ธฐ, ์ฆ‰ ์—ฐ๊ฒฐ๋ฆฌ์ŠคํŠธ์˜ ๊นƒ์ˆ˜ - ๊ฐ ์Šฌ๋กฏ์— ์ €์žฅ๋œ ํ‚ค์˜ ํ‰๊ท  ๊ฐฏ์ˆ˜ - ์—ฐ๊ฒฐ๋ฆฌ์ŠคํŠธ T[j]์˜ ๊ธธ์ด๋ฅผ Nj๋ผ๊ณ  ํ•˜๋ฉด, E[Nj] = alpha - ๋งŒ์•ฝ n = O(m)์ด๋ฉด ํ‰๊ท ๊ฒ€์ƒ‰์‹œ๊ฐ„์€ O(1) 2020. 11. 24.