μ½”λ”© ν…ŒμŠ€νŠΈ μ€€λΉ„/μ•Œκ³ λ¦¬μ¦˜

[μ•Œκ³ λ¦¬μ¦˜] 02. 선택 μ •λ ¬

μ£Όλ‹ˆμ“°πŸ§‘‍πŸ’» 2021. 9. 8. 09:00
728x90
λ°˜μ‘ν˜•

μ•ˆλ…•ν•˜μ„Έμš”? μ£Όλ‹ˆν•˜λž‘ μž…λ‹ˆλ‹€.

μ˜€λŠ˜μ€ μžλ£Œκ΅¬μ‘°μ™€ μ•Œκ³ λ¦¬μ¦˜μ˜ μ•Œκ³ λ¦¬μ¦˜μ—μ„œ Selection Sort에 λŒ€ν•΄ 곡뢀 ν•΄ 보도둝 ν•˜λŠ” κ²ƒμ΄μ—μš”.

μ†ŒμŠ€ μ½”λ“œμ— λŒ€ν•΄μ„œ 확인 ν•˜κ³  μ‹ΆμœΌμ‹  λΆ„λ“€κ»˜μ„œλŠ” μ£Όλ‹ˆν•˜λž‘μ˜ Git hub에 관심을 μ£Όμ„Έμš”!



 


 

 

 

 

πŸ“Œ Selection Sort (선택 μ •λ ¬)λž€?


선택 정렬은 μ£Όμ–΄μ§„ Data 쀑 μ΅œμ†Œκ°’μ„ 찾게 λ˜λŠ” κ²ƒμ΄μ—μš”.

그런 λ’€ ν•΄λ‹Ή μ΅œμ†Œκ°’μ„ 맨 μ•žμ— μœ„μΉ˜ν•œ κ°’κ³Ό 자리λ₯Ό λ°”κΎΈκ²Œ λœλ‹΅λ‹ˆλ‹€.

λ§ˆμ§€λ§‰μœΌλ‘œ 맨 μ•žμ˜ μœ„μΉ˜λ₯Ό λΊ€ λ‚˜λ¨Έμ§€ Dataλ₯Ό λ™μΌν•œ λ°©λ²•μœΌλ‘œ λ°˜λ³΅ν•˜λŠ” κ²ƒμ΄μ—μš”.

이미 μ΅œμ†Œκ°’μœΌλ‘œ μžλ¦¬κ°€ 이동 된 것듀은 λ‹€μ‹œ 자리 이동을 ν•  ν•„μš”κ°€ μ—†μœΌλ‹ˆ μ •λ ¬μ˜ μˆ˜λŠ” n -1 만큼 μ€„μ–΄λ“œλŠ” κ²ƒμ΄μ—μš”.

 

μ°Έκ³  μ‚¬μ΄νŠΈ : https://visualgo.net/ko/sorting

 

VisuAlgo - Sorting (Bubble, Selection, Insertion, Merge, Quick, Counting, Radix)

VisuAlgo is free of charge for Computer Science community on earth. If you like VisuAlgo, the only payment that we ask of you is for you to tell the existence of VisuAlgo to other Computer Science students/instructors that you know =) via Facebook, Twitter

visualgo.net

 

 

 

좜처:  https://en.wikipedia.org/wiki/Selection_sort

 

 

πŸ“Œ ν•„κΈ° 자료


 

 

 

 

πŸ“Œ μ•Œκ³ λ¦¬μ¦˜ κ΅¬ν˜„


    πŸ“ Python

for stand in range(len(data_list) - 1 # 둜 반볡
	lowest = stand					  # 둜 μ„ μ–Έ 및 μ΄ˆκΈ°ν™”
    
    for num in range(stand, len(data_list)	# stand λΆ€ν„° 데이터 길이 (λ°°μ—΄μ˜ 길이) - 1κΉŒμ§€ 반볡
    	λ‚΄λΆ€ 반볡문 μ•ˆμ—μ„œ data_list[lowest] > data_list[num]	# 이면,
        	lowest = num	#	비ꡐ λŒ€μƒ κΈ°μ€€ Index에 비ꡐ λŒ€μƒ Indexλ₯Ό λ„£μ–΄μ€€λ‹€.
            
    data_list[num], data_list[lowest] data_list[lowest], data_list[num]	# ν•΄λ‹Ή μœ„μΉ˜μ˜ 값듀을 μœ„μΉ˜ μ΄λ™ν•œλ‹€.

 

 

 

πŸ“Œ λΉ…μ˜€ ν‘œκΈ°λ²•μ— μ˜ν•œ μ‹œκ°„ λ³΅μž‘λ„


반볡문이 λ‘κ°œ 이고, κ·Έ μ•ˆμ—μ„œ data_list의 길이가 영ν–₯을 주기에 O($n^2$) μΈ κ²ƒμ΄μ—μš”.

쑰금 더 깊게 μƒμ„Έν•˜κ²Œ 계산을 ν•œλ‹€λ©΄ $\frac { n * (n - 1)}{ 2 }$ μ΄λžλ‹ˆλ‹€!

 

 


 

 

μ£Όλ‹ˆν•˜λž‘μ˜ 글이 λ§ˆμŒμ— λ“œμ…¨λ‚˜μš”? ꡬ독과 곡감! 그리고, λŒ“κΈ€μ€ μ£Όλ‹ˆν•˜λž‘μ—κ²Œ λ§Žμ€ 힘이 λ©λ‹ˆλ‹€

 

728x90
λ°˜μ‘ν˜•