CS/Data Structure

[python] 이진 트리 (binary tree) - κ°œλ… 정리

deo2kim 2020. 9. 1. 20:53
λ°˜μ‘ν˜•

πŸ“— 이진 트리 (binary tree)

μ΄μ§„νŠΈλ¦¬λž€ μ΅œλŒ€ 두 개의 μžμ‹(없을 μˆ˜λ„ 있음)을 κ°€μ§€λŠ” 트리 ν˜•νƒœμ˜ μžλ£Œκ΅¬μ‘°μ΄λ‹€.

탐색을 ν•˜κ±°λ‚˜ 정렬을 ν•˜λŠ”λ° μžˆμ–΄ 맀우 효율적으둜 μ‚¬μš©λœλ‹€.

νƒμƒ‰μ˜ μ‹œκ°„λ³΅μž‘λ„λŠ” ν‰κ· μ μœΌλ‘œ  O(logn) 이닀.

 

πŸ”΅ 이진 탐색 트리(binary search tree)

 

이진 탐색 νŠΈλ¦¬λŠ” 이진 트리의 ν•˜λ‚˜μ΄λ‹€.

λ…Έλ“œμ— λŒ€ν•΄μ„œ μ™Όμͺ½ μžμ‹μ˜ 값은 λ…Έλ“œμ˜ 값보닀 μž‘κ±°λ‚˜ κ°™κ³ , 였λ₯Έμͺ½ μžμ‹μ€ λ…Έλ“œμ˜ 값보닀 크닀.

μ•„λž˜μ˜ 그림을 보면 [21, 28, 14, 32, 25, 18, 11, 30, 19, 15]의 μˆœμ„œλŒ€λ‘œ 이진 탐색 트리λ₯Ό κ΅¬ν˜„ν•˜λŠ” 과정을 λ‚˜νƒ€λ‚΄κ³  μžˆλ‹€. κ°€μž₯ 처음의 값은 root λ…Έλ“œκ°€ 되고, λ‹€μŒ κ°’λΆ€ν„° λ…Έλ“œμ™€μ˜ λŒ€μ†Œ 비ꡐ관계에 따라 μœ„μΉ˜λ₯Ό κ²°μ •ν•œλ‹€.

이진 탐색 트리 κ΅¬ν˜„

 

 

πŸ”΅ 이진 탐색 트리 Search

μ•„λž˜μ˜ 그림을 보면 μœ„μ—μ„œ κ΅¬ν˜„ν•œ 이진 탐색 νŠΈλ¦¬μ—μ„œ 27을 μ°ΎλŠ” 과정을 λ‚˜νƒ€λ‚Έλ‹€. 이진 탐색 νŠΈλ¦¬λŠ” κ·Έ 밑에 λ³΄μ΄λŠ” μ •λ ¬λœ λ¦¬μŠ€νŠΈλ³΄λ‹€ 더 효율적으둜 μ›ν•˜λŠ” 값을 찾을 수 μžˆλ‹€.

이진 탐색 트리 μ„œμΉ˜

 

 


이미지 좜처: https://blog.penjee.com/

 

Penjee, Learn to Code | The Fun way

In short, a floating point number is number that represents decimal values like 3.1415 Contrast that with an integer like 11 . Demo Python Code The code below declares and then prints the data type, in Python, of a floating point number and an integer.

blog.penjee.com

 

λ°˜μ‘ν˜•