00:01
Let's use binary search to look for the index of 120 in the array above.
00:05
So here we have the index numbers and these are the values in the index and we are searching the values to look for the index of the value of 120.
00:15
So in binary search we begin with a low and a high of the entire array.
00:19
So basically this means that we believe 120 to be in between 0 and 8.
00:25
Okay, so now we look at the midpoint of 0 and 8.
00:29
So what is the midpoint of 0 and 8? well, 0 plus 8 over 2, floor of that.
00:34
So that means 0 plus 8 is 8 divided by 2 is 4.
00:38
We round it down to the closest integer which is 4.
00:42
So the midpoint is 4.
00:43
So we're looking at 57.
00:46
Now 120 is bigger than 57 which means that 120 exists to the right of 57.
00:55
So our new low is going to be to the right of 57 which is 5 and our high stays the same.
01:01
Now we are just looking at the array, sort of this part of the array.
01:07
We're looking at this part of the array now.
01:11
Good, so we calculate the new midpoint and we use the same sort of formula where we have the floor function...