Quicksort (sometimes called partition-exchange sort) is an efficient sorting algorithm, serving as a systematic method for placing the elements of an array in order. Developed by Tony Hoare in 1959 and published in 1961, it is still a commonly used algorithm for sorting.
2. IntroductionIntroduction
Quick sort is an example of divide and conquer algorithm. It
was developed in1960 by Tony Hoare. It is a recursive
algorithm.The intutive idea is as follows:
Divide:- Choose any element of the list, say the last element
as a pivot value. Remove the pivot from the list. Divide the
remaining elements into two parts,left and right,such that all
the elements equal to or less than the pivot are in the left list,
while the elements greater than the pivot are in right list.
Conquer:-Sort the two halves recursively using quick sort.
Combine:-Return sorted_left + pivot + sorted_right,as your
final sorted_list.
3. History of Quick Sort AlgorithmHistory of Quick Sort Algorithm
While studying at Moscow State University, Tony Hoare
received an offer of employment from
National Physical Laboratory (NPL) to work on new project
for machine translation form Russian to English. However
,because dictionaries were sorted into alphabetical order
before translation. Hoare thought of two methods to solve
this problem.The first method would have taken an amount
of time proportional to the square of the length of a
sentence. The second method would later manifest as
quicksort.
During this course, Hoare programmed an ultra-fast sorting
algorithm now known as quicksort. His paper on Quicksort
was also published in 1961,with another following in 1962.
7. Algorithm For Quick SortAlgorithm For Quick Sort
Quick( A, N, Beg, End , Loc)
Here A is an array of N elements .Parameters Beg and End contain
the boundary values of the sublist to which this procedure applies.
Loc keeps track of the position of the first element A[Beg] of the
sublist during the procedure. The local variable Left and Right will
contain the boundary values of the list of elements that have not
been scanned.
1. [Initialize].Set Left:= Beg, Right:=End and Loc:=Beg.
2. [Scan from right to left]
a) Repeat while A[Loc]<=A[Right] and Loc!=Right. Right:=Right-1
[End of Loop]
b) If Loc=Right, then: return.
c) If A[Loc]>A[Right],then:
i. Interchange A[loc] and A[Right].
ii. Set Loc:=Right.
iii. Go to Step 3.
8. 3. [Scan from left to right]
a) Repeat while A[Left]<=A[Loc] and Left!=Loc: Left :=Left+1.
b) If Loc=Left , then return.
c) if A[Left]>A[Loc],then
i. Interchange A[Left] and A[Loc].
ii. Set Loc:=Left
iii. Go to Step 2.
[End of if structure].
10. ConclusionConclusion
We discussed the history of the algorithm. Then implemented
the code in codeblocks. Quick sort is an efficient algorithm and
has an average running time of O(n*log(n)).While the worst-case
running time for quick sort is higher than that of the merge sort,
in practice quick sort works slightly faster the the merge sort.