- Unity
- Spring
- C++
- GIT
- SQL
- SSL
- MAKE US
- aligoapi
- mysql
- μμ€ν μννΈμ¨μ΄
- merge sort
- κ΅¬κΈ μμ λ‘κ·ΈμΈ
- Java
- node js
- docker
- Data Structure
- ν¨μ€νΈμΊ νΌμ€XμΌλμ
- springμΌλ‘ https μ μ©
- DATABASE
- MethodArgumentNotValidException
- datagrip
- 리λ μ€ λͺ λ Ήμ΄
- spring κ΅¬κΈ μμ λ‘κ·ΈμΈ
- spring μμ λ‘κ·ΈμΈ
- java error
- RP 2κΈ°
- Rp2κΈ°
- OpenAPI
- Quick Sort
- @CreatedDate
YS's develop story
μμ°¨ νμ, μ΄μ§ νμ μ 리 λ³Έλ¬Έ
π©π» μμ°¨ νμ(Sequential Search)κ³Ό μ΄μ§ νμ(Binary Search) μ 리
π₯ μμ°¨ νμ(Sequential Search)
λ°μ΄ν°κ° λ΄κ²¨μλ 리μ€νΈλ₯Ό μμμλΆν° νλμ© μ΄ν΄λ³΄μμ μνλ λ°μ΄ν°λ₯Ό μ°Ύλ λ°©λ²μ λλ€.
π μμ°¨ νμ μ½λ
def sequentialSearch(list, search):
for index in range(len(list)):
if list[index] == search:
return True
return False
βοΈ μμ°¨ νμ μκ° λ³΅μ‘λ
μ°Ύκ³ μ νλ κ°μ΄ 리μ€νΈμ 맨 λ§μ§λ§μ μμ λ, 리μ€νΈμ κΈΈμ΄λ§νΌ λ°μ΄ν°λ₯Ό λΉκ΅ν΄μΌ ν©λλ€.
λ°λΌμ μκ° λ³΅μ‘λλ O(n)μ λλ€.
π³ μ΄μ§ νμ (Binary Search)
νμν λ°μ΄ν°λ₯Ό μ νν λ°μΌλ‘ λλμ΄ νμͺ½μ λ°μ΄ν°κ° μλ€λ©΄ νμͺ½μ λ²λ¦¬λ©΄μ νμνλ λ°©λ²μ λλ€.
λ¨, μ΄μ§ νμμ λ°μ΄ν°κ° 미리 μ λ ¬λμ΄ μμ΄μΌμ§ μ¬μ©ν μ μμ΅λλ€.
π μ΄μ§ νμ μ½λ
def binarySearch(list, search):
print(list)
if len(list) == 1 and list[0] == search:
return True
if len(list) == 1 and list[0] != search:
return False
if len(list) == 0:
return False
medium = len(list) // 2
if list[medium] == search:
return True
else:
if list[medium] < search:
return binarySearch(list[medium + 1:], search)
else:
return binarySearch(list[:medium], search)
βοΈ μ΄μ§ νμ μκ° λ³΅μ‘λ
리μ€νΈλ₯Ό λ§€λ² 2κ°λ‘ λλμ΄ 1μ΄ λ λκΉμ§ λΉκ΅ μ°μ°μ μ§ννκΈ° λλ¬Έμ μκ° λ³΅μ‘λλ O(log n)μ λλ€.
'Algorithm' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
그리λ μκ³ λ¦¬μ¦ μ 리 (0) | 2021.08.13 |
---|---|
λλΉ μ°μ νμ (BFS), κΉμ΄ μ°μ νμ (DFS) μ 리 (0) | 2021.08.03 |
ν΅ μ λ ¬ (Quick Sort) μ 리 (0) | 2021.07.31 |
λ³ν© μ λ ¬ (Merge Sort) μ 리 (0) | 2021.07.31 |
λμ κ³νλ²κ³Ό λΆν μ 볡 μ 리 (0) | 2021.07.30 |