FAANG Coding Interviews / Data Structures and Algorithms / Leetcode
Пікірлер: 18
@GregHogg5 ай бұрын
Master Data Structures & Algorithms For FREE at AlgoMap.io!
@andrewhting5 ай бұрын
No bro, I’m so lost. Can you break it down even further for us noobs 😭
@nice-vf4rj5 ай бұрын
@andrewhting how would you search a sorted list of numbers? From start to end or divide and conquer
@mujtabarehman52555 ай бұрын
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_12055 ай бұрын
Remember that the list MUST be sorted, otherwise it won't work
@sealzz73764 ай бұрын
I was about to ask that too. Isn’t there a function for sorting it already in python?
@400elochess4 ай бұрын
@@sealzz7376numpy's np.sort
@aayushsamal27152 ай бұрын
@@sealzz7376 there is indeed... just remember to use it
@mohammedadel78495 ай бұрын
This can also be done recursively, but then the space complexity increases.
@pangzlab5 ай бұрын
Nice video. Forgot one critical thing, it should be sorted first to be able to perform this operation.
@GregHogg5 ай бұрын
"Given a sorted list of numbers", yes indeed it does. Thank you
@observer39875 ай бұрын
👍🏼 what's the step over this in terms of complexity?
@okcomputer21125 ай бұрын
What
@mujtabarehman52555 ай бұрын
O(log n), since the search space divides in half each time
@putuadibrata5 ай бұрын
please make another one, but the list is not sorted. Thank you
@nigh_anxiety5 ай бұрын
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).