[์ •๋ ฌ] 4.๋ณ‘ํ•ฉ์ •๋ ฌ(Merge sort)

๋“ค์–ด๊ฐ€๊ธฐ ์ „์—, ๋ฌธ์ œ์—์„œ ์ฃผ์–ด์ง„ '์ •๋ ฌํ•  ๋Œ€์ƒ์˜ ๊ฐฏ์ˆ˜'๊ฐ€ ์ปค์ง€๋ฉด ์ •๋ ฌ์ด ์–ด๋ ต๋‹ค. ๊ทธ๊ฒƒ์— ๋Œ€ํ•œ ํ•ด๊ฒฐ์ฑ…์€? ๋ถ„ํ•  ์ •๋ณต ๊ธฐ๋ฒ•(Divide-and-Conquer) STEP 1. ์›๋ž˜ ๋ฌธ์ œ๋ฅผ ๋…๋ฆฝ์ ์œผ๋กœ ํ’€ ์ˆ˜ ์žˆ๋Š” ์ž‘์€ ๋ฌธ์ œ๋กœ ๋‚˜๋ˆ”(Divide) STEP 2. ๊ฐ๊ฐ์˜ ๋ฌธ์ œ๋ฅผ ํ’‚(Delegate) STEP 3. ๊ฐ๊ฐ์˜ ๋ฌธ์ œ์˜ ๋‹ต์„ ์ด์šฉํ•ด ์›๋ž˜ ๋ฌธ์ œ์˜ ๋‹ต์„ ๋งŒ๋“ ๋‹ค.(Combine) ์ •๋ ฌ์„ ์œ„ํ•œ ๋ถ„ํ•  ์ •๋ณต ๊ธฐ๋ฒ•์€ ๋Œ€ํ‘œ์ ์œผ๋กœ ๋‘ ๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค. 1. ๋ณ‘ํ•ฉ ์ •๋ ฌ(Merge sort) 2. ํ€ต ์ •๋ ฌ(Quick sort) ๋ณธ๊ฒฉ์ ์œผ๋กœ ๋ณ‘ํ•ฉ ์ •๋ ฌ์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž. ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ๊ธฐ๋ณธ ์•„์ด๋””์–ด Divide - ์ •๋ ฌํ•  ๋ฆฌ์ŠคํŠธ๋ฅผ ์•ž ์ชฝ ๋ฐ˜, ๋’ค์ชฝ ๋ฐ˜์œผ๋กœ ๋‚˜๋ˆˆ๋‹ค. Half Delegate(Front) - ์•ž ์ชฝ ๋ฐ˜์„ ์ •๋ ฌํ•œ๋‹ค. Half De..

[์ •๋ ฌ] 3.์‚ฝ์ž… ์ •๋ ฌ

์‚ฝ์ž… ์ •๋ ฌ - ์ด๋ฏธ ์ •๋ ฌ๋œ ๋ถ€๋ถ„์€ ํ•ญ์ƒ ์ •๋ ฌ๋˜์–ด ์žˆ๋‹ค. - ์ฒ˜์Œ์—๋Š” ์ •๋ ฌ๋œ ๋ถ€๋ถ„์— ์›์†Œ๊ฐ€ 1๊ฐœ - ๋งค๋ฒˆ, ์ •๋ ฌํ•  ๋ถ€๋ถ„์˜ ์›์†Œ 1๊ฐœ๋ฅผ ์ด๋ฏธ ์ •๋ ฌ๋œ ๋ถ€๋ถ„์œผ๋กœ ์˜ฎ๊ธด๋‹ค. ์‹œ๊ฐ„ ๋ณต์žก๋„ Θ(n^2) - ๊ฐ€์žฅ ์ข‹์„ ๋•Œ: ์ด๋ฏธ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ๋˜์–ด ์žˆ์„ ๋•Œ -> ์ด n-1 ๋ฒˆ = Θ(n) - ์ตœ์•…์˜ ๊ฒฝ์šฐ: ์—ญ์ˆœ์œผ๋กœ ์ •๋ ฌ๋˜์–ด ์žˆ์„ ๋•Œ i๋ฒˆ์งธ ์œ„์น˜์˜ ์›์†Œ๋ฅผ ์ •๋ ฌ๋œ ๋ถ€๋ถ„์— ์ถ”๊ฐ€ํ•  ๋•Œ, i-1 ๊ฐœ์˜ ์›์†Œ์™€ ๋ชจ๋‘ ๋น„๊ตํ•ด์•ผํ•œ๋‹ค. i = 2,3, ..., n์ผ ๋•Œ ๊ฐ๊ฐ ๋น„๊ตํ•ด์•ผํ•  ๊ฐœ์ˆ˜๋Š” 1+ 2+ ... + n-1 = n(n-1)/2 = Θ(n^2) ์‚ฝ์ž… ์ •๋ ฌ Python ์ฝ”๋“œ def insertionSort(): nums = list(map(int, input().split(' '))) for i in range(1, len(n..

๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday
ยซ   2025/01   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
๊ธ€ ๋ณด๊ด€ํ•จ
250x250