Binary Search in Python: Python's Bisect Method

preview_player
Показать описание
In this video, we will be writing a function that takes an array of sorted integers and a key and returns the index of the first occurrence of that key from the array.

For example, for the array:
[-14, -10, 2, 108, 108, 243, 285, 285, 285, 401]

with target = 108, the algorithm would return 3, as the first occurrence of 108 in the above array is located at index 3.

This video is one part of the Binary Search playlist on my channel. For more videos on binary search and how to apply it to various problems, check out the other videos:

The software written in this video is available at:

Do you like the development environment I'm using in this video? It's a customized version of vim that's enhanced for Python development. If you want to see how I set up my vim, I have a series on this here:

If you've found this video helpful and want to stay up-to-date with the latest videos posted on this channel, please subscribe:
Рекомендации по теме
Комментарии
Автор

Very nice tutorial :). Please keep uploading such interesting videos. Really helpful.

divyanshupreti
Автор

If the number is not present in the list then bisect_left() and bisect_right() both return the index position where that number should be inserted to keep the list sorted even after insertion, isn't it?

shivamshrey
Автор

thank you for the video, learnt a lot!

artix
Автор

if the list is'nt sorted, will the bisect_left and bisect_right work??

TJ-woxt
Автор

What is the cost for the insertion O(n) in the worst case? Or they use smth fancy here?

thebestofthebest
Автор

what is the complexity of insort function?

ameynaik
join shbcf.ru