Binary Search in Python

Publicado em: 02 Novembro 2023
no canal de: 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


Nesta página do site você pode assistir ao vídeo on-line Binary Search in Python duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Kenny Yip Coding 02 Novembro 2023, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 1,381 vezes e gostou 15 espectadores. Boa visualização!