Introduction to Algorithms (Insertion Sort, Merge Sort)
程序员文章站
2024-03-18 08:11:16
...
The problem of sorting
Input: array A[1…n] of numbers.
Output: permutation B[1…n] of A such that B[1] ≤ B[2] ≤ … ≤ B[n] .
Why Sorting
- Obvious applications
- Problems that become easy once items are in sorted order
Insertion Sort
Insertion-Sort(A, n):
for j ← 2 to n:
insert key A[j] into the (already sorted) sub-array A[1 .. j-1].
by pairwise key-swaps down to its right position
Merge Sort
Merge-Sort A[1 .. n]:
1. If n = 1, done (nothing to sort).
2. Otherwise, recursively sort A[1 .. n/2] and A[n/2+1 .. n].
3. “Merge” the two sorted sub-arrays.
上一篇: Sort Algorithms
下一篇: 牛顿法求平方根
推荐阅读
-
Sort Algorithms
-
Introduction to Algorithms (Insertion Sort, Merge Sort)
-
Java数据结构及算法实例:插入排序 Insertion Sort
-
Java数据结构及算法实例:插入排序 Insertion Sort
-
Oracle执行计划中的连接方式nested loops join、sort merge joinn、hash join
-
PHP排序算法之直接插入排序(Straight Insertion Sort)实例分析
-
python基本算法之实现归并排序(Merge sort)
-
PHP排序算法之直接插入排序(Straight Insertion Sort)实例分析
-
排序合并连接(sort merge join)的原理
-
温故知新:合并排序(merge sort)及优化方法