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
In questa pagina del sito puoi guardare il video online Binary Search in Python della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Kenny Yip Coding 02 novembre 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 1,381 volte e gli è piaciuto 15 spettatori. Buona visione!