00:01
All right, so here we're using two different sorting algorithms to sort a list.
00:05
So we have 7, 4, 3, 8, 1, 5, 4, and 2.
00:19
Okay, so first we're going to use the insertion sort.
00:23
So we will grab the second element in the list and ask ourselves, is it larger than 7? so is 4 larger than 7? the answer is no, so we're going to insert it at the beginning.
00:35
So that's going to give us 4 -7 for our sorted portion and 381 -5 -4 -2 as the unsorted portion.
00:46
And that took one comparison for the first step.
00:50
We'll do the same thing.
00:51
We'll take the three and say, is three larger than four? and the answer is no.
00:57
So that gives us 3 -4 -7 sorted portion and 8154 -2 -2 -4 -2 -4 -4 -2.
01:07
For unsorted and that again just took one comparison.
01:11
So we'll grab the eight and say, is eight larger than three? yes, is it larger than four? yes, is it larger than seven? yes, okay, so three comparisons, all to find out we didn't need to move it.
01:25
And so our list is three, four, seven, eight, four, sorted, and one, five, four, two, unsorted.
01:33
And then we'll do the same thing.
01:35
So is one greater than three.
01:40
The answer is no.
01:42
So give us one comparison and we can put the one there.
01:47
So we get one, three, four, seven, eight, and five, four, two left.
01:56
So we'll grab the five and say is five greater than one? yes.
02:01
Is it greater than three? yes.
02:03
Is it greater than four? yes.
02:04
Is it greater than seven? no.
02:06
Okay, so that was four comparisons.
02:11
And now we can insert it here after the four.
02:16
One, three, four, five, seven, eight, and four, and two remaining.
02:24
So we're getting near the end here, so grab this four, and say, is it greater than one? yes, is it greater than three? yes.
02:34
Is it greater than four? no.
02:36
Okay, so that took three comparisons.
02:40
So you can insert that, and we just have one value remaining.
02:48
So that's the two, and so we'll take the two and say, is it greater than one.
02:52
Yes, it is.
02:53
Is it greater than three, no it is not.
02:56
So that took two comparisons.
03:01
So that would be one, two, three, four, four, five, seven, and eight.
03:06
And so if we tally up the comparisons at every step here, we get 15 of them.
03:17
So then we'll do the same thing here for the binary insertion of sort.
03:22
And the difference is that we're going to be using the binary search algorithm.
03:30
Them in the sorted portions of our list.
03:36
So if we start with, perhaps a new page is a good idea.
03:44
So we'll start with our list of 7, 4, 3, 8, 1, 5, 4, and 2.
04:00
And so it's going to start out the same way, where we compare 7 and 4 to get one comparison.
04:08
And it starts us off with 4 -7 -381 -5 -4 -2.
04:21
Okay, so now what's going to happen is when we compare the, when we want to start comparing the three, we're going to use the binary search algorithm.
04:31
So what that involves is saying, well, we want to take index 1, add it to index 2 for 3, divided by two for one and a half take the floor of that so round down for one and that's what we want to compare the three two so we'll ask ourselves is three is three greater than four and the answer there is no okay so that because that's just the one comparison in order to be able to insert it so it's 3, 4, 7, 8, 1, 5, 4, 2.
05:26
Okay, so this time we're taking the 8, but we want to do the same thing.
05:29
So we're taking, define what we're going to compare it to.
05:33
We'll take index 1, add it to index 3.
05:38
It's going to be a total of 4...