00:01
It's clarissa enumerate.
00:02
So for a, we have bubble sort, which successfully compares two adjacent elements and sorts them in decreasing order.
00:10
So let's say the list contains n elements.
00:15
So the first pass, we compare n minus one pairs of adjacent elements.
00:23
So there's n minus one comparisons.
00:25
For the second one, we make n minus two pairs of adjacent elements.
00:29
So there's n minus two comparisons.
00:31
And for the third pass, we compare n minus three pairs of adjacent elements.
00:35
So there's n minus three comparisons.
00:38
So the bubble sort algorithm stops if we make one comparison in some pass, which is as known as the last pass.
00:46
So let's say, like we said, there's going to be n elements.
00:52
So the bubble sort algorithm will stop when it's n minus one elements.
00:57
So the number of comparisons is equal to i'll put number of c for short is equal to n minus 1 plus n minus 2 plus n minus 3 all the way till plus 1, which is then equal to the sum notation of n minus 1, i equals 1 for i.
01:33
And since the sum notation for n minus 1 to n for i is equal to n times n plus 1 over 2, we know the number of comparisons is going to be equal to n minus 1 times n over 2, which is equal to n square minus 2 over 2.
02:04
So if we would then have a list of 2n elements instead, we would have 2n square minus 2 comparisons.
02:14
So we note that the number of comparisons more than doubled and less than quadruples when the size of the list increases from n to 2n.
02:26
So for part b, we have our insertion sort, which compares the first, the second element, with the first and correctly sorts the two numbers.
02:40
So it takes the next element afterwards and correctly inserts it in the part of the string that we know is correctly sorted and so on...