Binary Search in Python

Published: 02 November 2023
on channel: Kenny Yip Coding
1,381
15

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:
   • Python Data Structures and Algorithms  

Github: https://github.com/ImKennyYip/python-...

Subscribe for more coding tutorials 😄!

⭐ If you enjoyed the tutorial and would like to support the channel, you can do so here 💖: https://buymeacoffee.com/kennyyipcoding


On this page of the site you can watch the video online Binary Search in Python with a duration of hours minute second in good quality, which was uploaded by the user Kenny Yip Coding 02 November 2023, share the link with friends and acquaintances, this video has already been watched 1,381 times on youtube and it was liked by 15 viewers. Enjoy your viewing!