Algorithm 101----QUick Sort
2014-05-28 23:12
288 查看
My used to cover this topic in late 2012 or early 2013 when I was struggling to have a basic understanding about what computer science.
When I first read this algorithm I thought it was darn complicated and I never memorized how this algorithm worked concretely. So I decided to revisit this old acquaintance again!
I am not going to cover all the details of implementation of this algorithm but simply have a brief summary about the fundamental principles underlying:
1.first of all, just like merge-sort algorithm, this sorting algorithm is also based on divide-conquer paradigm : we first partition a full-length array into 2 segments, then quick sort the new sub-array. Keeping this dividing procedure until we get to
leaf node.
2. Secondly, the pseudocode of quick-sort goes as follows
It can be divided into two major steps:
step 1: partition.
partition ( array, l, r)
pivot=l;
i( represents the partition pointer that separate <pivot and > pivot parts ) =l+1;
j(represents the pointer that the algorithm is currently pointing)=l+1;
for j=l+1:1+r
if array[j]<pivot
swap(array[i], array[j]);
i++;
divide conquer:
quicksort (array, l ,r)
if (l<r)
{
partition(array,l,r);
quicksort( the first split);
quicksort(the second split)
}
The time complexity of quick sort is nlogn
When I first read this algorithm I thought it was darn complicated and I never memorized how this algorithm worked concretely. So I decided to revisit this old acquaintance again!
I am not going to cover all the details of implementation of this algorithm but simply have a brief summary about the fundamental principles underlying:
1.first of all, just like merge-sort algorithm, this sorting algorithm is also based on divide-conquer paradigm : we first partition a full-length array into 2 segments, then quick sort the new sub-array. Keeping this dividing procedure until we get to
leaf node.
2. Secondly, the pseudocode of quick-sort goes as follows
It can be divided into two major steps:
step 1: partition.
partition ( array, l, r)
pivot=l;
i( represents the partition pointer that separate <pivot and > pivot parts ) =l+1;
j(represents the pointer that the algorithm is currently pointing)=l+1;
for j=l+1:1+r
if array[j]<pivot
swap(array[i], array[j]);
i++;
divide conquer:
quicksort (array, l ,r)
if (l<r)
{
partition(array,l,r);
quicksort( the first split);
quicksort(the second split)
}
The time complexity of quick sort is nlogn
相关文章推荐
- Collection of algorithm for sorting. 常见排序算法集(三) —— Quick Sort
- Algorithm 101----merge sort
- Algorithm backup ---- Quick Sort(快速排序算法)
- Algorithm Intro - Quick Sort
- Algorithm Part I:Quick Sort
- 最大流的算法小结 Algorithm for Maximum Flow
- 大数据算法课程笔记8a:page replacement algorithm
- 101与金根回顾敏捷个人:(13)敏捷个人和敏捷开发
- JavaShowAlgorithm-Median of Two Sorted Arrays
- UVa Problem 101 - The Blocks Problem
- CDT、Modbus、103、101、104、DL/T645通讯规约的区别 目前电力系统主要为有线通讯,其中包括串口,网口,光口。分布式光伏有时还会用到无线通讯。通讯的规约种类也是比较多,下
- (EM算法)The EM Algorithm
- 计算1*2*3+3*4*5+.......+99*100*101的值
- [Algorithm]连通性问题 Connectivity Problem
- 计算1*2*3+3*4*5+...+99*100*101
- Kahan summation algorithm
- 物体空间姿态估计// Robust Planar Pose (RPP)algorithm
- vi编辑器打开大文件报错0602-101 Out of memory saving lines for undo
- java中判断 101-200 之间有多少个素数,并输出所有的素数
- [algorithm] 如何计算一个树的最远点.