The Binary Search Algorithm (+ Python Code Solution)

  Рет қаралды 20,084

Greg Hogg

Greg Hogg

3 ай бұрын

FAANG Coding Interviews / Data Structures and Algorithms / Leetcode

Пікірлер: 18
@GregHogg
@GregHogg 3 ай бұрын
Master Data Structures & Algorithms For FREE at AlgoMap.io!
@andrewhting
@andrewhting 3 ай бұрын
No bro, I’m so lost. Can you break it down even further for us noobs 😭
@nice-vf4rj
@nice-vf4rj 3 ай бұрын
​@andrewhting how would you search a sorted list of numbers? From start to end or divide and conquer
@mujtabarehman5255
@mujtabarehman5255 3 ай бұрын
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.
@greensalad_1205
@greensalad_1205 3 ай бұрын
Remember that the list MUST be sorted, otherwise it won't work
@sealzz7376
@sealzz7376 2 ай бұрын
I was about to ask that too. Isn’t there a function for sorting it already in python?
@400elochess
@400elochess 2 ай бұрын
​@@sealzz7376numpy's np.sort
@aayushsamal2715
@aayushsamal2715 17 күн бұрын
@@sealzz7376 there is indeed... just remember to use it
@mohammedadel7849
@mohammedadel7849 3 ай бұрын
This can also be done recursively, but then the space complexity increases.
@pangzlab
@pangzlab 3 ай бұрын
Nice video. Forgot one critical thing, it should be sorted first to be able to perform this operation.
@GregHogg
@GregHogg 3 ай бұрын
"Given a sorted list of numbers", yes indeed it does. Thank you
@observer3987
@observer3987 3 ай бұрын
👍🏼 what's the step over this in terms of complexity?
@okcomputer2112
@okcomputer2112 3 ай бұрын
What
@mujtabarehman5255
@mujtabarehman5255 3 ай бұрын
O(log n), since the search space divides in half each time
@putuadibrata
@putuadibrata 3 ай бұрын
please make another one, but the list is not sorted. Thank you
@nigh_anxiety
@nigh_anxiety 3 ай бұрын
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 3 ай бұрын
@@nigh_anxietyok
Binary Search Algorithm - Computerphile
18:34
Computerphile
Рет қаралды 158 М.
Опасность фирменной зарядки Apple
00:57
SuperCrastan
Рет қаралды 12 МЛН
Schoolboy - Часть 2
00:12
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 4,3 МЛН
НРАВИТСЯ ЭТОТ ФОРМАТ??
00:37
МЯТНАЯ ФАНТА
Рет қаралды 8 МЛН
ОБЯЗАТЕЛЬНО СОВЕРШАЙТЕ ДОБРО!❤❤❤
00:45
Understanding B-Trees: The Data Structure Behind Modern Databases
12:39
LSTM Time Series Forecasting Tutorial in Python
29:53
Greg Hogg
Рет қаралды 202 М.
Top 7 Algorithms for Coding Interviews Explained SIMPLY
21:22
Codebagel
Рет қаралды 342 М.
Data Science Coding is Hard. You can't do this. What's the reality?
18:17
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 288 М.
Binary Search Animated
7:00
Dreams of Code
Рет қаралды 27 М.
What REALLY is Data Science? Told by a Data Scientist
11:09
Joma Tech
Рет қаралды 3,8 МЛН
25 Nooby Pandas Coding Mistakes You Should NEVER make.
11:30
Rob Mulla
Рет қаралды 265 М.
Binary Search - A Different Perspective | Python Algorithms
8:56
Опасность фирменной зарядки Apple
00:57
SuperCrastan
Рет қаралды 12 МЛН