YS's develop story

ํ€ต ์ •๋ ฌ (Quick Sort) ์ •๋ฆฌ ๋ณธ๋ฌธ

Algorithm

ํ€ต ์ •๋ ฌ (Quick Sort) ์ •๋ฆฌ

Yusang 2021. 7. 31. 15:59

๐Ÿ‘ฉ‍๐Ÿ’ป ํ€ต ์ •๋ ฌ (Quick Sort) ์ •๋ฆฌ with Python 

๐Ÿฅ˜ ํ€ต ์ •๋ ฌ (Quick Sort)์ด๋ž€?

๐ŸŒธ ์ •๋ ฌ ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ๊ฝƒ, Quick Sort

  1. ๊ธฐ์ค€์  (Pivot)์„ ์ •ํ•ด์„œ, ๊ธฐ์ค€์ ๋ณด๋‹ค ์ž‘์€ ๋ฐ์ดํ„ฐ๋Š” ์™ผ์ชฝ, ํฐ ๋ฐ์ดํ„ฐ๋Š” ์˜ค๋ฅธ์ชฝ์œผ๋กœ ๋ชจ์œผ๋Š” ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.
  2. ๋‚˜๋ˆ„์–ด์ง„ ์™ผ์ชฝ, ์˜ค๋ฅธ์ชฝ ๋ฐ์ดํ„ฐ๋ฅผ ์žฌ๊ท€ ์šฉ๋ฒ•์„ ์‚ฌ์šฉํ•ด์„œ ๋‹ค์‹œ ๋™์ผ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์œ„ ์ž‘์—…์„ ๋ฐ˜๋ณตํ•ฉ๋‹ˆ๋‹ค.
  3. ํ•จ์ˆ˜๋Š” ์™ผ์ชฝ, Pivot, ์˜ค๋ฅธ์ชฝ์„ ๋ฆฌํ„ดํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
  4. Divde And Conquer ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋Š” ๋Œ€ํ‘œ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.

 

๐Ÿณ ํ€ต ์ •๋ ฌ ๊ตฌํ˜„ with Python

# QuickSort
def quickSort(list):
    if len(list) <= 1:
        return list
    pivot = list[0]
    left = [items for items in list[1:] if items < pivot]
    right = [items for items in list[1:] if items >= pivot]
    return quickSort(left) + [pivot] + quickSort(right)

 

๐Ÿช ์‹œ๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

Comments