Комментарии:
Why is there no condition for when target is < left or > right? Or just plain =left or =right?
Ответитьthank you...
Ответитьthank you
ОтветитьHelp me give me your number
ОтветитьYou're great. The explanations are really broken down. Thank you👍
ОтветитьLots of verbal pauses, uhhh, make for difficult listening, ahh
ОтветитьThank you for this video. That was a really clear explanation
ОтветитьGreat video as always
ОтветитьI know this is old but what software were you using to create this ?
Awesome video by the way. I was having trouble understanding the pointer aspect on codecademy but seeing the visuals helped a lot
thanks a lot!
ОтветитьThe link does not work anymore, maybe you can add a new one in the video description. Thank you
Ответить# This is code for rotated array. First we define function for rotate array in particular direction then we give input that rotated array in Binary search code.
# If the code will help you please like the comment.
def rotate_ntime(arr,direction, n):
if direction=="Left":
for i in range(n):
left_rotate_one(arr)
if direction=="Right":
for i in range(n):
right_rotate_one(arr)
return arr
def left_rotate_one(arr):
temp=arr[0]
for i in range(len(arr)-1):
arr[i]=arr[i+1]
arr[len(arr)-1]=temp
return arr
def right_rotate_one(arr):
temp=arr[len(arr)-1]
for i in range(len(arr)-1,0,-1):
arr[i]=arr[i-1]
arr[0]=temp
return arr
arr=[8,9,11,13,-2,3,4,7]
arr=rotate_ntime(arr,"Left",4)
print(arr)
def Binary_search(arr,target):
low=0
high=len(arr)-1
while low<=high:
mid = (low + high) // 2
if arr[mid]==target:
return mid
elif arr[mid]<target:
low=mid+1
else:
high=mid-1
print(Binary_search(arr,11))
no i dont wanna be a software engineer at google..
i hate you algo expert.
okay bye
Clean explanation! Thank you so much!
ОтветитьNice Dojo
ОтветитьWhat app do you use to draw these examples?
Ответитьwhy u gotta check n/2 elements
its a computer always starts from 0 to n numbers
search(array, the value u r searching for)
so where did the n/2 come from ?
is it something i should just memorize ?
Hi you implemented to binary search wrong, how you calculate mid will can give you an overflow - you should correct it to this : mid = left + (right - left) /2
Maybe point this out so you don't teach something wrong to other students.
But else great video !
do you have a tutoral on Hash maps, Stacks/Queues/Heap/Priority Queue ?
ОтветитьIt's not obvious how much binary search helps until you actually code it and time it yourself. It's actually amazing. Thanks for the informative videos!
ОтветитьI have tried the python example in JavaScript
function binarySearch(arr, target) {
let left = 0;
let right = arr.length - 1;
arr = arr.sort((a, b) => a - b)
while (left <= right) {
let mid = Math.floor((left + right) / 2);
if (arr[mid] == target) {
return mid
} else if (target < arr[mid]) {
right = mid - 1
} else {
left = mid + 1
}
}
return -1
}
binarySearch([2, 1, 13, 3, 10, 8, 6, 0, 12,16], 8)
Ok, so binary search only works if the list is sorted or sorted+shift, correct?
But, I then I have a question. Why not check if the target is more or less than the range of values before starting the loop? We just assume that’s less likely to happen so we’d rather go straight to checking targets which can be found first? As in, “hey, if you sent us a target that doesn’t fit in the list, you’re gonna have to wait.”
your videos are so helpful, dude. tysm! ;u;
ОтветитьThank you so much, you helped me a lot!
ОтветитьThe arr[mid] don´t accept float numbers, let's say we an array of 8 elements which means that the right value will be 7 (len(arr) - 1), so the division is 7/2 = 3.5 and that's a float number which allowed in mid. I round the value in python, but it gets me a "None" answer when a I use arrays like [1,3,5,7,9,11,13,15], what you suggest me to do?
Ответитьactually if the target is 12, the search would end with left being 7 and right being 6.
Not left being 6 and right being 5.
But whatever. :P
Cool stuff
thanks fam <3
ОтветитьThank u a lot!
ОтветитьTHANK YOU! for saving me always. Your tutorials are easy to understand compared to others. Great teacher!
ОтветитьThank You!!
ОтветитьYou just made it so simple!
Thanks
what if the value youre looking for is in L or R?
ОтветитьThank you!!!
ОтветитьPlease HELP
Why should we use array.length -1 as the index in Python is from 0 to 9 but using range (0,(array.length) will EXCLUDe last number from the calculations.
Thanks in Advance!!!!!
best lecture👌🏻
ОтветитьGreat explanation thanks
Ответитьgreat explanation
ОтветитьPeople who trying to get into google .
Is python usefull to get into google
Thank you sirr👏👏👏
ОтветитьYou made it so simple.
Ответитьsuch a good explanation!
ОтветитьI'm very new to this and have watched a few of these videos and found them interesting.
What I don't understand though, is what the arrays and targets may relate to? Like what industry problem could be solved by these methods?
If someone could explain that or point me in the right direction would be appreciated.