How to Implement Binary Search from Scratch in Javascript

preview_player
Показать описание
In this video, we cover:
0:24 how binary search works using a practical example
1:59 how to pseudocode an implementation
5:04 an iterative solution in javascript
9:20 a recursive solution in javascript
12:56 time and space complexity analysis

Рекомендации по теме
Комментарии
Автор

Hey. Calculating mid as (left + right) / 2 will lead to overflow for large enough input size. Instead, it's recommended to find it as left + (right - left) / 2 which takes care of the overflow.

archiekesseler
Автор

such a smooth explanation! will never forget binary search.

abhisheksrivastava
Автор

Really liked Helper function, Thanks @Coderbyte

kduisheev
Автор

By far the best video explanation! Clear and and well explained.

jhonymaurad
Автор

Thank you so much mam.
Very cool teaching mam totally understandable

driveinspire
Автор

Thank you for explaining this so clearly!

Ringo_Panda
Автор

it will better work if you put in left = -1 and right = array.lenght in the begin))))

ВладимирАндреев-фт
Автор

Thank you! But for the iterative way, shouldn't we use "while (left <= right)" instead of "while (left < right)"? So that we can find the target at index 0 or index length - 1.

as
Автор

is there a inbuilt function for binary search in js?.

pendyalaabhishek
Автор

So, what is faster, array.indexOf(target) or this code...

minnuss
Автор

binarySearch([1, 2, 3], 1)
this will return false. does anyone know why? the middle, start and end all are at the same spot. but it will not evaluate if(arr[mid] === target) condition.

numantayyebi
welcome to shbcf.ru