SlideShare a Scribd company logo
1 of 13
Download to read offline
Algorithm
Binary Search
Bill Kim(김정훈) | ibillkim@gmail.com
목차
•Linear Search
•Binary Search
•Concept
•Features
•Implementation
•References
Linear Search
Linear Search는 가장 단순한 방식의 탐색 방법입니다.
배열의 요소를 처음부터 끝까지 순차적으로 순회하며 원하는 요소
를 찾는 방식입니다.
최악의 경우는 모든 배열을 순회하고 나서야 값을 찾거나 찾지 못
할 수 있습니다.
따라서 시간복잡도가 0(n)이 될 수 있는 알고리즘입니다.
Binary Search
Binary Search이란 이진 탐색으로서 단순한 선형 탐색(Linear
Search)와 달리 절반씩 배열을 줄여나가면서 찾는 탐색 알고리즘
입니다.
단 이진 탐색 알고리즘을 실행하기 위해서는 배열의 요소가 정렬이
되어있어야 하는 단점이 있습니다.
Concept
이진 탐색의 과정을 보면 아래와 같은 방식으로 탐색을 합니다.
1. 배열의 중앙 값(middle
index)을 찾습니다.
2. 찾고자하는 값과 중앙값
을 비교하여 작으면 왼쪽,
크면 오른쪽의 요소들의 배
열의 중앙값을 다시 찾습
니다.
3. 현재 중앙값의 요소와 찾
고자하는 값을 계속 비교
하며 찾을때까지 2번의 과
정을 반복합니다.
Features
이진 탐색은 아래와 같은 특징을 가진 알고리즘입니다.
1. 기본적으로 배열을 절반으로 나누면서 탐색을 하는 방식
2. 탐색 전에 배열이 정렬이 되어 있어야 함
3. 시간복잡도는 O(logn)의 속도를 가짐
4. 알고리즘의 복잡도가 높지 않으며 효율이 선형 탐색보다 좋음
Implementation
Swift를 활용하여 이진 탐색 알고리즘을 살펴보겠습니다.
아래는 기본적으로 오른차순으로 정렬된 배열을 기준으로하여 탐색
하는 알고리즘이니다.
func binarySearch<T: Comparable>(array: [T], item: T) -> Int {
var low = 0
var high = array.count - 1
while low <= high {
let mid = (low + high) / 2
let guess = array[mid]
if guess == item {
return mid
} else if guess > item {
high = mid - 1
} else {
low = mid + 1
}
}
return -1
}
Implementation
아래와 같이 재귀 호출 방식으로도 이진 탐색 알고리즘을 구현할
수 있습니다.
func binarySearch(first: Int, last: Int, target: Int, array: [Int]) -> Int {
if first > last {
return -1
}
let middle = (first + last) / 2
if target == array[middle] {
return middle
} else {
if target < array[middle] {
return binarySearch(first: first, last: middle-1, target: target,
array: array)
} else {
return binarySearch(first: middle+1, last: last, target: target,
array: array)
}
}
}
Implementation
let numbers = [-1, 0, 1, 2, 5, 13, 15, 20, 45, 51, 59, 68, 77]
print("Index : (binarySearch(array: numbers, item: 1))") // Index : 2
print("Index : (binarySearch(array: numbers, item: 68))") // Index : 11
print("Index : (binarySearch(array: numbers, item: 99))") // Index : -1
print("Index : (binarySearch(first: 0, last: numbers.count, target: 1, array:
numbers))") // Index : 2
References
[1] [Swift] Swift로 Binary Search( 이진 탐색 알고리즘 )를 구
현해보자 : https://eunjin3786.tistory.com/32
[2] Play With Code: Binary Search In Swift : https://
learnappmaking.com/binary-search-swift-how-to/
[3] Swift, Algorithm, linear Search & Binary Search :
https://devmjun.github.io/archive/BinarySearch
[4] How to implement Binary Search in Swift? : https://
medium.com/@notestomyself/how-to-implement-binary-
search-in-swift-6867840302ed
[5] Divide and Conquer with Binary Search in Swift :
https://mikebuss.com/2016/04/21/binary-search/
References
[6] Binary Search Array Extension in Swift : https://
agostini.tech/2017/01/30/binary-search-array-
extension-in-swift/
[7] Swift Algorithms – Binary Search : https://
www.seemuapps.com/swift-algorithms-binary-search
[8] 이진 검색(Binary Search) : https://kka7.tistory.com/77
[9] Algorithm) 이진 탐색(Binary Search) in Swift : https://
atelier-chez-moi.tistory.com/88
[10] [스위프트:알고리즘] 이진 탐색[1 / 3]: Binary Search: 이진
탐색이 뭐야? : https://the-brain-of-sic2.tistory.com/42
References
[11] Swift로 자료구조, 알고리즘 공부하기 (1) - Binary
Search : https://kor45cw.tistory.com/1
Thank you!

More Related Content

What's hot

파이썬 자료형 발표
파이썬 자료형 발표파이썬 자료형 발표
파이썬 자료형 발표joonjhokil
 
110120 binary search
110120 binary search110120 binary search
110120 binary searchYeayoung Ha
 
[Algorithm] Quick Sort
[Algorithm] Quick Sort[Algorithm] Quick Sort
[Algorithm] Quick SortBill Kim
 
[Swift] Data Structure - Heap
[Swift] Data Structure - Heap[Swift] Data Structure - Heap
[Swift] Data Structure - HeapBill Kim
 
R과 기초통계 : 01.자료다루기
R과 기초통계 : 01.자료다루기R과 기초통계 : 01.자료다루기
R과 기초통계 : 01.자료다루기Yoonwhan Lee
 
R과 기초통계 : 02.기술통계-자료나타내기
R과 기초통계 : 02.기술통계-자료나타내기R과 기초통계 : 02.기술통계-자료나타내기
R과 기초통계 : 02.기술통계-자료나타내기Yoonwhan Lee
 
R 기초 : R Basics
R 기초 : R BasicsR 기초 : R Basics
R 기초 : R BasicsYoonwhan Lee
 
[Swift] Data Structure - Binary Tree
[Swift] Data Structure - Binary Tree[Swift] Data Structure - Binary Tree
[Swift] Data Structure - Binary TreeBill Kim
 
통계자료 분석을 위한 R
통계자료 분석을 위한 R통계자료 분석을 위한 R
통계자료 분석을 위한 RYoonwhan Lee
 
Start IoT with JavaScript - 4.객체1
Start IoT with JavaScript - 4.객체1Start IoT with JavaScript - 4.객체1
Start IoT with JavaScript - 4.객체1Park Jonggun
 
제4장 sql 함수를 사용해보기
제4장 sql 함수를 사용해보기제4장 sql 함수를 사용해보기
제4장 sql 함수를 사용해보기sang doc Lee
 
Start IoT with JavaScript - 2.연산자
Start IoT with JavaScript - 2.연산자Start IoT with JavaScript - 2.연산자
Start IoT with JavaScript - 2.연산자Park Jonggun
 
Scala스터디 - 배열사용하기
Scala스터디 - 배열사용하기Scala스터디 - 배열사용하기
Scala스터디 - 배열사용하기창규 김
 
알고리즘 스터디(정렬) Seungdols
알고리즘 스터디(정렬) Seungdols알고리즘 스터디(정렬) Seungdols
알고리즘 스터디(정렬) Seungdolsseungdols
 

What's hot (19)

파이썬 자료형 발표
파이썬 자료형 발표파이썬 자료형 발표
파이썬 자료형 발표
 
110120 binary search
110120 binary search110120 binary search
110120 binary search
 
[Algorithm] Quick Sort
[Algorithm] Quick Sort[Algorithm] Quick Sort
[Algorithm] Quick Sort
 
[Swift] Data Structure - Heap
[Swift] Data Structure - Heap[Swift] Data Structure - Heap
[Swift] Data Structure - Heap
 
R과 기초통계 : 01.자료다루기
R과 기초통계 : 01.자료다루기R과 기초통계 : 01.자료다루기
R과 기초통계 : 01.자료다루기
 
R과 기초통계 : 02.기술통계-자료나타내기
R과 기초통계 : 02.기술통계-자료나타내기R과 기초통계 : 02.기술통계-자료나타내기
R과 기초통계 : 02.기술통계-자료나타내기
 
R 기초 : R Basics
R 기초 : R BasicsR 기초 : R Basics
R 기초 : R Basics
 
Python 스터디
Python 스터디Python 스터디
Python 스터디
 
[Swift] Data Structure - Binary Tree
[Swift] Data Structure - Binary Tree[Swift] Data Structure - Binary Tree
[Swift] Data Structure - Binary Tree
 
통계자료 분석을 위한 R
통계자료 분석을 위한 R통계자료 분석을 위한 R
통계자료 분석을 위한 R
 
Apply교육
Apply교육Apply교육
Apply교육
 
Start IoT with JavaScript - 4.객체1
Start IoT with JavaScript - 4.객체1Start IoT with JavaScript - 4.객체1
Start IoT with JavaScript - 4.객체1
 
제4장 sql 함수를 사용해보기
제4장 sql 함수를 사용해보기제4장 sql 함수를 사용해보기
제4장 sql 함수를 사용해보기
 
Haskell study 4
Haskell study 4Haskell study 4
Haskell study 4
 
Start IoT with JavaScript - 2.연산자
Start IoT with JavaScript - 2.연산자Start IoT with JavaScript - 2.연산자
Start IoT with JavaScript - 2.연산자
 
R 기초 II
R 기초 IIR 기초 II
R 기초 II
 
DM_02
DM_02DM_02
DM_02
 
Scala스터디 - 배열사용하기
Scala스터디 - 배열사용하기Scala스터디 - 배열사용하기
Scala스터디 - 배열사용하기
 
알고리즘 스터디(정렬) Seungdols
알고리즘 스터디(정렬) Seungdols알고리즘 스터디(정렬) Seungdols
알고리즘 스터디(정렬) Seungdols
 

Similar to [Algorithm] Binary Search

Binary Search
Binary SearchBinary Search
Binary Searchskku_npc
 
개경프 1주차 Stl study
개경프 1주차 Stl study개경프 1주차 Stl study
개경프 1주차 Stl study경 송
 
[Swift] Data Structure - Binary Search Tree
[Swift] Data Structure - Binary Search Tree[Swift] Data Structure - Binary Search Tree
[Swift] Data Structure - Binary Search TreeBill Kim
 
Python_numpy_pandas_matplotlib 이해하기_20160815
Python_numpy_pandas_matplotlib 이해하기_20160815Python_numpy_pandas_matplotlib 이해하기_20160815
Python_numpy_pandas_matplotlib 이해하기_20160815Yong Joon Moon
 
[SOPT] 데이터 구조 및 알고리즘 스터디 - #03 : 정렬 (기본, 효율, 초효율
[SOPT] 데이터 구조 및 알고리즘 스터디 - #03 : 정렬 (기본, 효율, 초효율[SOPT] 데이터 구조 및 알고리즘 스터디 - #03 : 정렬 (기본, 효율, 초효율
[SOPT] 데이터 구조 및 알고리즘 스터디 - #03 : 정렬 (기본, 효율, 초효율S.O.P.T - Shout Our Passion Together
 
자료구조 Project6
자료구조 Project6자료구조 Project6
자료구조 Project6KoChungWook
 
Python+numpy pandas 4편
Python+numpy pandas 4편Python+numpy pandas 4편
Python+numpy pandas 4편Yong Joon Moon
 
Python+numpy pandas 1편
Python+numpy pandas 1편Python+numpy pandas 1편
Python+numpy pandas 1편Yong Joon Moon
 
2.linear regression and logistic regression
2.linear regression and logistic regression2.linear regression and logistic regression
2.linear regression and logistic regressionHaesun Park
 
Project#5 최단거리 찾기 D0 Hwp
Project#5 최단거리 찾기 D0 HwpProject#5 최단거리 찾기 D0 Hwp
Project#5 최단거리 찾기 D0 HwpKimjeongmoo
 
[Algorithm] Merge Sort
[Algorithm] Merge Sort[Algorithm] Merge Sort
[Algorithm] Merge SortBill Kim
 
04. binary search
04. binary search04. binary search
04. binary search승혁 조
 
Linq to object using c#
Linq to object using c#Linq to object using c#
Linq to object using c#병걸 윤
 
자료구조5보고서
자료구조5보고서자료구조5보고서
자료구조5보고서KimChangHoen
 
캐빈머피 머신러닝 Kevin Murphy Machine Learning Statistic
캐빈머피 머신러닝 Kevin Murphy Machine Learning Statistic캐빈머피 머신러닝 Kevin Murphy Machine Learning Statistic
캐빈머피 머신러닝 Kevin Murphy Machine Learning Statistic용진 조
 
자바로 배우는 자료구조
자바로 배우는 자료구조자바로 배우는 자료구조
자바로 배우는 자료구조중선 곽
 
알고리즘과제2.pdf
알고리즘과제2.pdf알고리즘과제2.pdf
알고리즘과제2.pdftangtang1026
 

Similar to [Algorithm] Binary Search (20)

Binary Search
Binary SearchBinary Search
Binary Search
 
알고리즘
알고리즘알고리즘
알고리즘
 
개경프 1주차 Stl study
개경프 1주차 Stl study개경프 1주차 Stl study
개경프 1주차 Stl study
 
[Swift] Data Structure - Binary Search Tree
[Swift] Data Structure - Binary Search Tree[Swift] Data Structure - Binary Search Tree
[Swift] Data Structure - Binary Search Tree
 
Python_numpy_pandas_matplotlib 이해하기_20160815
Python_numpy_pandas_matplotlib 이해하기_20160815Python_numpy_pandas_matplotlib 이해하기_20160815
Python_numpy_pandas_matplotlib 이해하기_20160815
 
[SOPT] 데이터 구조 및 알고리즘 스터디 - #03 : 정렬 (기본, 효율, 초효율
[SOPT] 데이터 구조 및 알고리즘 스터디 - #03 : 정렬 (기본, 효율, 초효율[SOPT] 데이터 구조 및 알고리즘 스터디 - #03 : 정렬 (기본, 효율, 초효율
[SOPT] 데이터 구조 및 알고리즘 스터디 - #03 : 정렬 (기본, 효율, 초효율
 
자료구조 Project6
자료구조 Project6자료구조 Project6
자료구조 Project6
 
Python+numpy pandas 4편
Python+numpy pandas 4편Python+numpy pandas 4편
Python+numpy pandas 4편
 
Python+numpy pandas 1편
Python+numpy pandas 1편Python+numpy pandas 1편
Python+numpy pandas 1편
 
2.linear regression and logistic regression
2.linear regression and logistic regression2.linear regression and logistic regression
2.linear regression and logistic regression
 
컴퓨터개론09
컴퓨터개론09컴퓨터개론09
컴퓨터개론09
 
Project#5 최단거리 찾기 D0 Hwp
Project#5 최단거리 찾기 D0 HwpProject#5 최단거리 찾기 D0 Hwp
Project#5 최단거리 찾기 D0 Hwp
 
[Algorithm] Merge Sort
[Algorithm] Merge Sort[Algorithm] Merge Sort
[Algorithm] Merge Sort
 
04. binary search
04. binary search04. binary search
04. binary search
 
Linq to object using c#
Linq to object using c#Linq to object using c#
Linq to object using c#
 
자료구조5보고서
자료구조5보고서자료구조5보고서
자료구조5보고서
 
캐빈머피 머신러닝 Kevin Murphy Machine Learning Statistic
캐빈머피 머신러닝 Kevin Murphy Machine Learning Statistic캐빈머피 머신러닝 Kevin Murphy Machine Learning Statistic
캐빈머피 머신러닝 Kevin Murphy Machine Learning Statistic
 
자바로 배우는 자료구조
자바로 배우는 자료구조자바로 배우는 자료구조
자바로 배우는 자료구조
 
알고리즘과제2.pdf
알고리즘과제2.pdf알고리즘과제2.pdf
알고리즘과제2.pdf
 
Light Tutorial Python
Light Tutorial PythonLight Tutorial Python
Light Tutorial Python
 

More from Bill Kim

[Algorithm] Sorting Comparison
[Algorithm] Sorting Comparison[Algorithm] Sorting Comparison
[Algorithm] Sorting ComparisonBill Kim
 
[Algorithm] Big O Notation
[Algorithm] Big O Notation[Algorithm] Big O Notation
[Algorithm] Big O NotationBill Kim
 
[Algorithm] Shell Sort
[Algorithm] Shell Sort[Algorithm] Shell Sort
[Algorithm] Shell SortBill Kim
 
[Algorithm] Radix Sort
[Algorithm] Radix Sort[Algorithm] Radix Sort
[Algorithm] Radix SortBill Kim
 
[Algorithm] Heap Sort
[Algorithm] Heap Sort[Algorithm] Heap Sort
[Algorithm] Heap SortBill Kim
 
[Algorithm] Bubble Sort
[Algorithm] Bubble Sort[Algorithm] Bubble Sort
[Algorithm] Bubble SortBill Kim
 
[Algorithm] Recursive(재귀)
[Algorithm] Recursive(재귀)[Algorithm] Recursive(재귀)
[Algorithm] Recursive(재귀)Bill Kim
 
[Swift] Data Structure - AVL
[Swift] Data Structure - AVL[Swift] Data Structure - AVL
[Swift] Data Structure - AVLBill Kim
 
[Swift] Data Structure - Graph(BFS)
[Swift] Data Structure - Graph(BFS)[Swift] Data Structure - Graph(BFS)
[Swift] Data Structure - Graph(BFS)Bill Kim
 
[Swift] Data Structure - Graph(DFS)
[Swift] Data Structure - Graph(DFS)[Swift] Data Structure - Graph(DFS)
[Swift] Data Structure - Graph(DFS)Bill Kim
 
[Swift] Data Structure - Tree
[Swift] Data Structure - Tree[Swift] Data Structure - Tree
[Swift] Data Structure - TreeBill Kim
 
[Swift] Data Structure - Graph
[Swift] Data Structure - Graph[Swift] Data Structure - Graph
[Swift] Data Structure - GraphBill Kim
 
[Swift] Data Structure - Dequeue
[Swift] Data Structure - Dequeue[Swift] Data Structure - Dequeue
[Swift] Data Structure - DequeueBill Kim
 
[Swift] Data Structure - Stack
[Swift] Data Structure - Stack[Swift] Data Structure - Stack
[Swift] Data Structure - StackBill Kim
 
[Swift] Data Structure - Queue
[Swift] Data Structure - Queue[Swift] Data Structure - Queue
[Swift] Data Structure - QueueBill Kim
 
[Swift] Data Structure - Linked List
[Swift] Data Structure - Linked List[Swift] Data Structure - Linked List
[Swift] Data Structure - Linked ListBill Kim
 
[Swift] Data Structure Introduction
[Swift] Data Structure Introduction[Swift] Data Structure Introduction
[Swift] Data Structure IntroductionBill Kim
 
Design Pattern Introduction
Design Pattern IntroductionDesign Pattern Introduction
Design Pattern IntroductionBill Kim
 
[Swift] Visitor
[Swift] Visitor[Swift] Visitor
[Swift] VisitorBill Kim
 
[Swift] Template Method
[Swift] Template Method[Swift] Template Method
[Swift] Template MethodBill Kim
 

More from Bill Kim (20)

[Algorithm] Sorting Comparison
[Algorithm] Sorting Comparison[Algorithm] Sorting Comparison
[Algorithm] Sorting Comparison
 
[Algorithm] Big O Notation
[Algorithm] Big O Notation[Algorithm] Big O Notation
[Algorithm] Big O Notation
 
[Algorithm] Shell Sort
[Algorithm] Shell Sort[Algorithm] Shell Sort
[Algorithm] Shell Sort
 
[Algorithm] Radix Sort
[Algorithm] Radix Sort[Algorithm] Radix Sort
[Algorithm] Radix Sort
 
[Algorithm] Heap Sort
[Algorithm] Heap Sort[Algorithm] Heap Sort
[Algorithm] Heap Sort
 
[Algorithm] Bubble Sort
[Algorithm] Bubble Sort[Algorithm] Bubble Sort
[Algorithm] Bubble Sort
 
[Algorithm] Recursive(재귀)
[Algorithm] Recursive(재귀)[Algorithm] Recursive(재귀)
[Algorithm] Recursive(재귀)
 
[Swift] Data Structure - AVL
[Swift] Data Structure - AVL[Swift] Data Structure - AVL
[Swift] Data Structure - AVL
 
[Swift] Data Structure - Graph(BFS)
[Swift] Data Structure - Graph(BFS)[Swift] Data Structure - Graph(BFS)
[Swift] Data Structure - Graph(BFS)
 
[Swift] Data Structure - Graph(DFS)
[Swift] Data Structure - Graph(DFS)[Swift] Data Structure - Graph(DFS)
[Swift] Data Structure - Graph(DFS)
 
[Swift] Data Structure - Tree
[Swift] Data Structure - Tree[Swift] Data Structure - Tree
[Swift] Data Structure - Tree
 
[Swift] Data Structure - Graph
[Swift] Data Structure - Graph[Swift] Data Structure - Graph
[Swift] Data Structure - Graph
 
[Swift] Data Structure - Dequeue
[Swift] Data Structure - Dequeue[Swift] Data Structure - Dequeue
[Swift] Data Structure - Dequeue
 
[Swift] Data Structure - Stack
[Swift] Data Structure - Stack[Swift] Data Structure - Stack
[Swift] Data Structure - Stack
 
[Swift] Data Structure - Queue
[Swift] Data Structure - Queue[Swift] Data Structure - Queue
[Swift] Data Structure - Queue
 
[Swift] Data Structure - Linked List
[Swift] Data Structure - Linked List[Swift] Data Structure - Linked List
[Swift] Data Structure - Linked List
 
[Swift] Data Structure Introduction
[Swift] Data Structure Introduction[Swift] Data Structure Introduction
[Swift] Data Structure Introduction
 
Design Pattern Introduction
Design Pattern IntroductionDesign Pattern Introduction
Design Pattern Introduction
 
[Swift] Visitor
[Swift] Visitor[Swift] Visitor
[Swift] Visitor
 
[Swift] Template Method
[Swift] Template Method[Swift] Template Method
[Swift] Template Method
 

[Algorithm] Binary Search

  • 3. Linear Search Linear Search는 가장 단순한 방식의 탐색 방법입니다. 배열의 요소를 처음부터 끝까지 순차적으로 순회하며 원하는 요소 를 찾는 방식입니다. 최악의 경우는 모든 배열을 순회하고 나서야 값을 찾거나 찾지 못 할 수 있습니다. 따라서 시간복잡도가 0(n)이 될 수 있는 알고리즘입니다.
  • 4. Binary Search Binary Search이란 이진 탐색으로서 단순한 선형 탐색(Linear Search)와 달리 절반씩 배열을 줄여나가면서 찾는 탐색 알고리즘 입니다. 단 이진 탐색 알고리즘을 실행하기 위해서는 배열의 요소가 정렬이 되어있어야 하는 단점이 있습니다.
  • 5. Concept 이진 탐색의 과정을 보면 아래와 같은 방식으로 탐색을 합니다. 1. 배열의 중앙 값(middle index)을 찾습니다. 2. 찾고자하는 값과 중앙값 을 비교하여 작으면 왼쪽, 크면 오른쪽의 요소들의 배 열의 중앙값을 다시 찾습 니다. 3. 현재 중앙값의 요소와 찾 고자하는 값을 계속 비교 하며 찾을때까지 2번의 과 정을 반복합니다.
  • 6. Features 이진 탐색은 아래와 같은 특징을 가진 알고리즘입니다. 1. 기본적으로 배열을 절반으로 나누면서 탐색을 하는 방식 2. 탐색 전에 배열이 정렬이 되어 있어야 함 3. 시간복잡도는 O(logn)의 속도를 가짐 4. 알고리즘의 복잡도가 높지 않으며 효율이 선형 탐색보다 좋음
  • 7. Implementation Swift를 활용하여 이진 탐색 알고리즘을 살펴보겠습니다. 아래는 기본적으로 오른차순으로 정렬된 배열을 기준으로하여 탐색 하는 알고리즘이니다. func binarySearch<T: Comparable>(array: [T], item: T) -> Int { var low = 0 var high = array.count - 1 while low <= high { let mid = (low + high) / 2 let guess = array[mid] if guess == item { return mid } else if guess > item { high = mid - 1 } else { low = mid + 1 } } return -1 }
  • 8. Implementation 아래와 같이 재귀 호출 방식으로도 이진 탐색 알고리즘을 구현할 수 있습니다. func binarySearch(first: Int, last: Int, target: Int, array: [Int]) -> Int { if first > last { return -1 } let middle = (first + last) / 2 if target == array[middle] { return middle } else { if target < array[middle] { return binarySearch(first: first, last: middle-1, target: target, array: array) } else { return binarySearch(first: middle+1, last: last, target: target, array: array) } } }
  • 9. Implementation let numbers = [-1, 0, 1, 2, 5, 13, 15, 20, 45, 51, 59, 68, 77] print("Index : (binarySearch(array: numbers, item: 1))") // Index : 2 print("Index : (binarySearch(array: numbers, item: 68))") // Index : 11 print("Index : (binarySearch(array: numbers, item: 99))") // Index : -1 print("Index : (binarySearch(first: 0, last: numbers.count, target: 1, array: numbers))") // Index : 2
  • 10. References [1] [Swift] Swift로 Binary Search( 이진 탐색 알고리즘 )를 구 현해보자 : https://eunjin3786.tistory.com/32 [2] Play With Code: Binary Search In Swift : https:// learnappmaking.com/binary-search-swift-how-to/ [3] Swift, Algorithm, linear Search & Binary Search : https://devmjun.github.io/archive/BinarySearch [4] How to implement Binary Search in Swift? : https:// medium.com/@notestomyself/how-to-implement-binary- search-in-swift-6867840302ed [5] Divide and Conquer with Binary Search in Swift : https://mikebuss.com/2016/04/21/binary-search/
  • 11. References [6] Binary Search Array Extension in Swift : https:// agostini.tech/2017/01/30/binary-search-array- extension-in-swift/ [7] Swift Algorithms – Binary Search : https:// www.seemuapps.com/swift-algorithms-binary-search [8] 이진 검색(Binary Search) : https://kka7.tistory.com/77 [9] Algorithm) 이진 탐색(Binary Search) in Swift : https:// atelier-chez-moi.tistory.com/88 [10] [스위프트:알고리즘] 이진 탐색[1 / 3]: Binary Search: 이진 탐색이 뭐야? : https://the-brain-of-sic2.tistory.com/42
  • 12. References [11] Swift로 자료구조, 알고리즘 공부하기 (1) - Binary Search : https://kor45cw.tistory.com/1