Binary Search
✅ Binary Search
search algorithm
used on sorted array
repeatedly divide search interval into two parts(binary) and search
- Sort
- set left, right, mid
- While left < right
- Compare mid and serach value
- If mid == search value, search terminates
- If mid < search value, search right
- If mid > search value, search left
- If mid < search value, search right
⭐️ Keyword
✅ Code
https://soheeparklee.github.io/posts/CT-1-51/
✅ Time complexity
O(log N) search interval is halved in each step
✅ Space complexity
O(1)
👍🏻 Pros
- do not have to search all the array, just search half
👎🏻 Cons
- array has to be sorted
💡 Reference
This post is licensed under CC BY 4.0 by the author.