MERGE-SORT: INTRODUCTION TO ALGORITHMS
来源:互联网 发布:js判断滚动条位置 编辑:程序博客网 时间:2024/05/18 00:23
Merge sort:归并排序
Animation
An example of merge sort. First divide the list into the smallest unit (1 element), then compare each element with the adjacent list to sort and merge the two adjacent lists. Finally all the elements are sorted and merged.
Merge sort animation. The sorted elements are represented by dots.
A recursive merge sort algorithm used to sort an array of 7 integer values. These are the steps a human would take to emulate merge sort (top-down).
Complexity
Pseudo code
MERGE-SORT(A,p,r) 1 if p<r 2 q = floor((p+r)/2) 3 MERGE-SORT(A,p,q) 4 MERGE-SORT(A,q+1,r) 5 MERGE(A,p,q,r)MERGE(A,p,q,r) 1 n1 = q-p+1 2 n2 = r-q 3 let L[1..n1+1] and R[1..n2+1] be new arrays 4 for i=1 to n1 5 L[i] = A[p+i-1] 6 for j=1 to n2 7 R[j] = A[q+j] 8 L[n1+1] = Infinite 9 R[n2+1] = Infinite10 i = 111 j = 112 for k=p to r13 if L[i] <= R[j]14 A[k] = L[i]15 i = i+116 else17 A[k] = R[j]18 j = j+1
Figure
Reference
<< Introduction to Algorithms >> Third Edition, THOMAS H. CORMEN, CHARLES E. LEISERSON, RONALD L. RIVEST, CLIFFORD STEIN.
https://en.wikipedia.org/wiki/Merge_sort
0 0
- MERGE-SORT: INTRODUCTION TO ALGORITHMS
- INSERTION-SORT: INTRODUCTION TO ALGORITHMS
- introduction to algorithms 菜鸟笔记 sort algorithms
- Introduction: Analysis of Algorithms, Insertion Sort, Merge Sort
- Quick sort implementation (Introduction to Algorithms)
- introduction to algorithms sorting lesson 2 merge sorting
- introduction to algorithms sorting lesson_6 Counting sort (计数排序)
- About Introduction to Algorithms
- Introduction to Algorithms
- Introduction to Algorithms
- BUBBLESORT: INTRODUCTION TO ALGORITHMS
- Introduction to Algorithms
- Introduction to Algorithm - Summary of Chapter 2(2) - Merge Sort
- Algorithms: Merge Sort -- 归并排序
- Introduction to String Searching Algorithms
- 《Introduction to Algorithms》Second Edition
- Book "Introduction to Algorithms" Got
- introduction to algorithms 笔记 AVLtree
- JBOSS EAP 6 系列六 公共模块的jar配置到jboss的modules详细配置
- Markdown如何满足中文阅读习惯实现首行缩进
- PHP中内存溢出的问题
- 解决一个千万级别的数组引发的问题的深入剖析
- 黑马程序员——集合框架详解
- MERGE-SORT: INTRODUCTION TO ALGORITHMS
- HDU ACM 4494 Teamwork 最小费用最大流
- 小结1
- BinTree::定义
- 小红帽免费酒店管理系统PMS
- 2015摩根士丹利(Morgan Stanley)实习电话面试
- 一个WordPress站点绑定多个域名
- Hadoop之——自定义分组比较器实现分组功能
- java常见笔试题,易犯错误区