Algorithmic Toolbox week4 Divide and Conquer --- Sorting Problem

Selection Problem

Algorithmic Toolbox week4 Divide and Conquer --- Sorting Problem_第1张图片
Selection Sort

Algorithmic Toolbox week4 Divide and Conquer --- Sorting Problem_第2张图片
image.png

Algorithmic Toolbox week4 Divide and Conquer --- Sorting Problem_第3张图片
image.png

Algorithmic Toolbox week4 Divide and Conquer --- Sorting Problem_第4张图片
image.png

Algorithmic Toolbox week4 Divide and Conquer --- Sorting Problem_第5张图片
image.png

Merge Sort

Algorithmic Toolbox week4 Divide and Conquer --- Sorting Problem_第6张图片
merge sort

Algorithmic Toolbox week4 Divide and Conquer --- Sorting Problem_第7张图片
image.png

Algorithmic Toolbox week4 Divide and Conquer --- Sorting Problem_第8张图片
image.png

Algorithmic Toolbox week4 Divide and Conquer --- Sorting Problem_第9张图片
image.png

For example, it is perfectly okay to sort the sequence of size 1 million, for example, 10 to the 6th, on your laptop using merge sort algorithm.

While for the quadratic time selection sort algorithm, sorting a sequence of size 10 to the 6th, 1 million, will take roughly 10 to the 12th operations, which is too much for modern computers.


Algorithmic Toolbox week4 Divide and Conquer --- Sorting Problem_第10张图片
image.png

Okay, so to prove this lemma, to prove the upper bound on the running time of the merge sort algorithm, first know that to merge two parts of size n over 2 of our initial array, takes the linear time.

Namely, big O of n, because while the left part has size n over 2, the right part has size n over 2. And for merging, we basically just combo these parts from left to right.

Algorithmic Toolbox week4 Divide and Conquer --- Sorting Problem_第11张图片
image.png

So now what we are going to do is to account for only the work done before the recursive calls and after the recursive calls at each separate level.And we know already that it takes linear time to do this. I mean, if we have an array of size n, it takes linear time to split it into two halves. And then it takes linear time to combine the result.

So in the next video, we will show that actually no algorithm, no comparison based algorithms, to be completely formal, can sort a given sequence of n elements asymptotically faster than in n log n time. Which actually means that the merge sort algorithm is asymptotically optimal.

你可能感兴趣的:(Algorithmic Toolbox week4 Divide and Conquer --- Sorting Problem)