Тёмный

The Binary Search Algorithm (+ Python Code Solution) 

Greg Hogg
Подписаться 200 тыс.
Просмотров 22 тыс.
50% 1

Опубликовано:

 

17 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 22   
@GregHogg
@GregHogg 6 месяцев назад
Master Data Structures & Algorithms For FREE at AlgoMap.io!
@andrewhting
@andrewhting 6 месяцев назад
No bro, I’m so lost. Can you break it down even further for us noobs 😭
@nice-vf4rj
@nice-vf4rj 6 месяцев назад
​@andrewhting how would you search a sorted list of numbers? From start to end or divide and conquer
@mujtabarehman5255
@mujtabarehman5255 6 месяцев назад
In most other languages, its better to do "left + (right - left) // 2", which is equal to "(right + left) // 2", except it takes away the chance of integer overflow. In Python it doesn't matter since numbers can theoretically be as large as needed.
@KonstantinS-p4g
@KonstantinS-p4g 7 дней назад
Nicely explained
@greensalad_1205
@greensalad_1205 6 месяцев назад
Remember that the list MUST be sorted, otherwise it won't work
@sealzz7376
@sealzz7376 5 месяцев назад
I was about to ask that too. Isn’t there a function for sorting it already in python?
@400elochess
@400elochess 4 месяца назад
​@@sealzz7376numpy's np.sort
@aayushsamal2715
@aayushsamal2715 3 месяца назад
@@sealzz7376 there is indeed... just remember to use it
@brandonampang2199
@brandonampang2199 9 дней назад
@@sealzz7376yes, but bubble sort would take a long time if the array is long
@brandonampang2199
@brandonampang2199 9 дней назад
Is it better to find the target number 1 by 1 on each index when the array is unsorted or just sort it and then find it using binary search?
@mohammedadel7849
@mohammedadel7849 6 месяцев назад
This can also be done recursively, but then the space complexity increases.
@muizHD
@muizHD 3 дня назад
Why is M under -1 when -1 + 0 // 2 = -0.5 always rounds down to 0, M should be = to 0 ?
@observer3987
@observer3987 6 месяцев назад
👍🏼 what's the step over this in terms of complexity?
@okcomputer2112
@okcomputer2112 6 месяцев назад
What
@mujtabarehman5255
@mujtabarehman5255 6 месяцев назад
O(log n), since the search space divides in half each time
@pangzlab
@pangzlab 6 месяцев назад
Nice video. Forgot one critical thing, it should be sorted first to be able to perform this operation.
@GregHogg
@GregHogg 6 месяцев назад
"Given a sorted list of numbers", yes indeed it does. Thank you
@putuadibrata
@putuadibrata 6 месяцев назад
please make another one, but the list is not sorted. Thank you
@nigh_anxiety
@nigh_anxiety 6 месяцев назад
Then binary search isn't possible, and you have to do a linear search. Or, if you expect to search the list multiple times, sort it first and then do binary search as in the video. It's not worth sorting and doing binary search if you're only going to search once because the best sorting is O(n log n) and a linear search is just O(n).
@putuadibrata
@putuadibrata 6 месяцев назад
@@nigh_anxietyok
Далее
3 Types of Algorithms Every Programmer Needs to Know
13:12
Binary Search Tree in Python
22:59
Просмотров 52 тыс.
Making an Algorithm Faster
30:08
Просмотров 121 тыс.
10 Crazy Python Operators That I Rarely Use
11:37
Просмотров 38 тыс.
How Binary Search Makes Computers Much, Much Faster
6:51
How I would learn Leetcode if I could start over
18:03
Просмотров 607 тыс.
why do void* pointers even exist?
8:17
Просмотров 373 тыс.
The Sad Reality of Being a Data Scientist
8:55
Просмотров 77 тыс.
Binary Search Animated
7:00
Просмотров 33 тыс.