您的位置:首页 > 产品设计 > UI/UE

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

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: