Binary Search in Python

Subscribers:
50,600
Published on ● Video Link: https://www.youtube.com/watch?v=VD-sj4IwZPE



Duration: 11:42
295 views
5


What is binary search and how to implement binary search in python. Binary search is a searching algorithm used to find a value in a sorted sequence. If the list is sorted, we can partition the list into 2 sublists using a midpoint index.

If the value at the midpoint is smaller than the target number, we can discard the left sublist and just check the right sublist. Else, if the value is bigger, then we can discard the right sublist and check the left subilst. This algorithm works because the list is sorted so you are guaranteed to avoid doing extra comparisons.

For this reason, the binary search algorithm has a run-time of O(log(n)), which is the number of times n can be divided by 2. This is more efficient than the linear search O(n) as we can quickly eliminate values in the list.

Python Playlist:
https://youtube.com/playlist?list=PLnKe36F30Y4bcRomKi02sP9NR27KnBqCK

Github: https://github.com/ImKennyYip/python-data-structures-algorithms

Subscribe for more coding tutorials 😄!







Tags:
binary search python
binary search in python
binary search with python
python binary search
how to code binary search in python
code binary search in python
code binary search python
implement binary search in python
implement binary search python
what is binary search
what is binary search python
binary search
binary search algorithm
binary search algorithm in python
binary search algorithm python
python binary search algorithm
python binary search explained