Sorting Algorithms Summary

Sorting Algorithms Summary


Comparison-based Sorting: 4
Decision Tree Model: for study the limit of comparison-based sorting
Prove: The lower bound of running time for any c-based sorting algorithm is nlogn
--> omega(nlogn), both of Heap Sort and Merge Sort are almost the best of them.

1. Insertion sort:
worst case theta(n^2)
suitable for the small size of input data
in-place sorting: 除待排序数组本身,仅有常数个元素需要存储

2. Merge sort:
theta(nlogn)
non-in-place sorting

3. Heap sort:
O(nlogn) in-place sorting

4. Quicksort:
in-place sorting worst case theta(n^2)
expected running time theta(nlogn)
in the real situation, it is faster than Heap Sort
与insertion sort类似,二者code紧凑,运行时间隐含常数系数很小
Suitable for the Large size of input data

Non-Comparison-based Sorting 
--it may break the lower bound of nlogn.
1. 计数排序
Counting Sort
假定输入元素值均在集合{0,1,2,..., k}内,用数组索引作为确定相对次序的工具
running time: theta(k+n)
k = O(n), linear time

2. 基数排序
Radix Sort
扩展计数排序的适用范围
n个整数,每个整数d位数字,每个数字可能值k个,基数排序在theta(d(n+k))完成
d = constant, k = O(n), linear time

3. Bucket Sort
需要了解输入数组的概率分布,对半开区间 [0,1)服从均匀分布的n个实数,平均情况O(n)

Algorithms      Worst Case      Average Case/ Expected Running time
Insertion           theta(n^2)                theta(n^2)
Merge               theta(nlogn)             theta(nlogn)
Heap                 O(nlogn)                  --
Quick                theta(n^2)                theta(nlogn)
Counting           theta(k+n)               theta(k+n)
Radix                theta(d(n+k))           theta(d(n+k))
Bucket              theta(n^2)                 theta(n)



评论

此博客中的热门博文

8 Link Analysis

1 Map reduce problems

NoSql and AWS DynamoDB practices