The Binary Search Algorithm (+ Python Code Solution)

  Рет қаралды 21,989

Greg Hogg

Greg Hogg

Күн бұрын

FAANG Coding Interviews / Data Structures and Algorithms / Leetcode

Пікірлер: 18
@GregHogg
@GregHogg 5 ай бұрын
Master Data Structures & Algorithms For FREE at AlgoMap.io!
@andrewhting
@andrewhting 5 ай бұрын
No bro, I’m so lost. Can you break it down even further for us noobs 😭
@nice-vf4rj
@nice-vf4rj 5 ай бұрын
​@andrewhting how would you search a sorted list of numbers? From start to end or divide and conquer
@mujtabarehman5255
@mujtabarehman5255 5 ай бұрын
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 5 ай бұрын
Remember that the list MUST be sorted, otherwise it won't work
@sealzz7376
@sealzz7376 4 ай бұрын
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 2 ай бұрын
@@sealzz7376 there is indeed... just remember to use it
@mohammedadel7849
@mohammedadel7849 5 ай бұрын
This can also be done recursively, but then the space complexity increases.
@pangzlab
@pangzlab 5 ай бұрын
Nice video. Forgot one critical thing, it should be sorted first to be able to perform this operation.
@GregHogg
@GregHogg 5 ай бұрын
"Given a sorted list of numbers", yes indeed it does. Thank you
@observer3987
@observer3987 5 ай бұрын
👍🏼 what's the step over this in terms of complexity?
@okcomputer2112
@okcomputer2112 5 ай бұрын
What
@mujtabarehman5255
@mujtabarehman5255 5 ай бұрын
O(log n), since the search space divides in half each time
@putuadibrata
@putuadibrata 5 ай бұрын
please make another one, but the list is not sorted. Thank you
@nigh_anxiety
@nigh_anxiety 5 ай бұрын
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 5 ай бұрын
@@nigh_anxietyok
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 565 М.
I Solved 100 LeetCode Problems
13:11
Green Code
Рет қаралды 61 М.
Binary Search Algorithm - Computerphile
18:34
Computerphile
Рет қаралды 161 М.
10 Crazy Python Operators That I Rarely Use
11:37
Indently
Рет қаралды 25 М.
Leetcode 46. Permutations : Introduction to backtracking
10:06
ComputerBread
Рет қаралды 98 М.
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 104 М.
3 Types of Algorithms Every Programmer Needs to Know
13:12
ForrestKnight
Рет қаралды 477 М.
The Sad Reality of Being a Data Scientist
8:55
Samson Afolabi
Рет қаралды 68 М.
How Binary Search Makes Computers Much, Much Faster
6:51
Tom Scott
Рет қаралды 1,4 МЛН
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 242 М.
How I Would Learn Python FAST in 2024 (if I could start over)
12:19
Thu Vu data analytics
Рет қаралды 375 М.