ํ’€์Šคํƒ ์›น๐ŸŒ ๊ฐœ๋ฐœ์ž ์ง€๋ง์ƒ ๐Ÿง‘๐Ÿฝโ€๐Ÿ’ป
โž• ์ธ๊ณต์ง€๋Šฅ ๊ด€์‹ฌ ๐Ÿค–


Categories


Recent views

  • 1
  • 2
  • 3
  • 4
  • 5

์ •๋ ฌ ์ •๋ฆฌ

์ •๋ ฌ ์ •๋ฆฌ

์ •๋ ฌ ๋ฐฉ๋ฒ• ์ตœ์  ํ‰๊ท  ์ตœ์•… ๊ณต๊ฐ„ ๋ณต์žก๋„
์„ ํƒ(selection) $O(n^2)$ $O(n^2)$ $O(n^2)$ $O(n^2)$
๋ฒ„๋ธ”(bubble) $O(n^2)$ $O(n^2)$ $O(n^2)$ $O(n)$
์‚ฝ์ž…(insert) $O(n)$ $O(n^2)$ $O(n^2)$ $O(n^2)$
๋ณ‘ํ•ฉ(merge) $O(n\log n)$ $O(n\log n)$ $O(n\log n)$ $O(n\log n)$
ํ€ต(quick) $O(n\log n)$ $O(n\log n)$ $O(n^2)$ $O(n\log n)$
ํž™(heap) $O(n\log n)$ $O(n\log n)$ $O(n\log n)$ $O(n)$
์‰˜(shell) $O(n^{1.25})$ $O(n^{1.25})$ $O(n^{1.25})$ $O(n)$
๊ณ„์ˆ˜(counting) $O(n+k)$ $O(n+k)$ $O(n+k)$ $O(n+k)$

์‹œ๊ฐ„ ๋ณต์žก๋„ $O(n^2)$

๋ฒ„๋ธ” ์ •๋ ฌ (Bubble Sort)

๊ตฌํ˜„์ด ์‰ฝ๋‹ค๋Š” ๊ฒƒ ์™ธ์—๋Š” ์•„๋ฌด๋Ÿฐ ์žฅ์ ์ด ์—†๋Š” ์ •๋ ฌ

์ด๋ฏธ ์ •๋ ฌ๋œ ์ž๋ฃŒ์—์„  1๋ฒˆ๋งŒ ๋Œ๋ฉด ๋˜๋ฏ€๋กœ ์ตœ์„ ์˜ ์„ฑ๋Šฅ์„ ๋ณด์—ฌ์คŒ($O(n)$), ๋”ฐ๋ผ์„œ ์ค‘๊ฐ„์— ์ •๋ ฌ์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๋ฐ”๋กœ ์ค‘๋‹จํ•˜๊ณ  ์ •๋ ฌ๋˜์ง€ ์•Š์•˜์Œ์„ ์•Œ๋ฆฌ๋Š”๋ฐ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

BubbleSort(eles[])
	for i = 0 to eles[].length-1
		for j = 0 to i-1
			if eles[j] > eles[j+1]
				swap(ele[j], eles[j+1])
	return eles[]

์„ ํƒ ์ •๋ ฌ(Selection Sort)

์ธ๊ฐ„์ด ๋ฌด์˜์‹์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ์ •๋ ฌ 1

๋ณดํ†ต ๋ฒ„๋ธ” ์ •๋ ฌ ๋ณด๋‹ค 2๋ฐฐ ์ •๋„ ๋น ๋ฅด๋‹ค.

SelectionSort(eles[])
	for i = 0 to eles[].length-2
		index = i
		for j = i + 1 to eles[].length-1
			if eles[index] > eles[j]
				index = j
		swap(eles[index], elses[i])
	return eles[]

์‚ฝ์ž… ์ •๋ ฌ(Insertion Sort)

์ธ๊ฐ„์ด ๋ฌด์˜์‹์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ์ •๋ ฌ 2

  • ํƒ์ƒ‰ ์ด์™ธ์˜ ์˜ค๋ฒ„ํ—ค๋“œ๊ฐ€ ์ ์–ด ์ด๋ฏธ ์ •๋ ฌ๋˜์–ด ์žˆ๋Š” ์ž๋ฃŒ๊ตฌ์กฐ์—์„œ ์ž๋ฃŒ๋ฅผ ํ•˜๋‚˜์”ฉ ์‚ฝ์ž…, ์ œ๊ฑฐํ•  ๋•Œ ์ข‹๋‹ค.
  • ๋ฐฐ์—ด์ด ์ž‘์€ ๊ฒฝ์šฐ์—๋„ ๋ฐ€์–ด๋‚ด๊ธฐ ๋ถ€๋ถ„์˜ ์˜ค๋ฒ„ํ—ค๋“œ๊ฐ€ ์ ์œผ๋ฏ€๋กœ ์™ ๋งŒํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜๋ณด๋‹ค ์ข‹๋‹ค.
InsertionSort(eles[])
	for i = 1 to eles[].length-1
		j = i - 1
		key = eles[i]
		while eles[j] > key and j >= 0
			eles[j+1] = eles[j]
			j = j -1
		eles[j+1] = key
	return eles[]

์ข€๋” ์ž์„ธํ•œ ์„ค๋ช…์€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์„ฑ๋Šฅ ๋ถ„์„ ์ฐธ์กฐ

์‹œ๊ฐ„ ๋ณต์žก๋„ $O(n\log n)$

๋ณ‘ํ•ฉ ์ •๋ ฌ(Merge Sort)

๋ณ‘ํ•ฉ ์ •๋ ฌ

ํž™ ์ •๋ ฌ(Heap Sort)

์ž๋ฃŒ๊ตฌ์กฐ์ธ ํž™์„ ์ด์šฉํ•œ ์ •๋ ฌ

์ถ”๊ฐ€์ ์ธ ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ์ „ํ˜€ ํ•„์š”ํ•˜์ง€ ์•Š๊ณ , ์–ธ์ œ๋‚˜ ์•ˆ์ •์ ์ธ $O(n\log n)$ ์„ฑ๋Šฅ์„ ๊ฐ€์ง„๋‹ค.
ํ•˜์ง€๋งŒ, ํ€ต ์ •๋ ฌ์ด ์ปดํ“จํ„ฐ ๊ตฌ์กฐ์ƒ ์บ์‹œ ์นœํ™”์ ์ด๋ฏ€๋กœ ๋ณดํ†ต ๋” ๋น ๋ฅด๋‹ค.

๋‹ค๋งŒ, ํ€ต ์ •๋ ฌ์€ ์ตœ์•…์˜ ์ƒํ™ฉ์—๋Š” $O(n^2)$์ด๋ฏ€๋กœ, ์ถ”๊ฐ€์ ์ธ ํ”ผ๋ด‡ ์„ ํƒ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์—†์„ ๊ฒฝ์šฐ ํž™ ์ •๋ ฌ์€ ์ตœ์•…์˜ ์ƒํ™ฉ์„ ํ”ผํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ€ต ์ •๋ ฌ(Quick Sort)

๋ณดํ†ต ์ตœ๊ณ ์˜ ์„ฑ๋Šฅ์„ ๋‚˜ํƒ€๋‚ด๋Š” ์ •๋ ฌ

ํ”ผ๋ด‡์˜ ์„ ํƒ์— ๋”ฐ๋ผ ์„ฑ๋Šฅ์ด ํฌ๊ฒŒ ๋‹ฌ๋ผ์ ธ, ํ”ผ๋ด‡์„ ๊ณ ๋ฅด๋Š” partition ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋˜ํ•œ ๋‹ค์–‘ํ•˜๊ฒŒ ์กด์žฌํ•œ๋‹ค.

๊ทธ์™ธ ์ •๋ ฌ

์…ธ ์ •๋ ฌ(Shellโ€™s Sort) - $O(n^{1.25})$

์‚ฝ์ž…์ •๋ ฌ์„ ๋„์—„๋„์—„ ๋จผ์ € ์ˆ˜ํ–‰ํ•œ ํ›„, ๊ฑฐ์˜ ์ •๋ ฌ๋œ ๋ฐฐ์—ด์„ ์‚ฝ์ž… ์ •๋ ฌ๋กœ ๋งˆ๋ฌด๋ฆฌํ•˜๋Š” ๋ฐฉ์‹ใ