1. Quick Sort in Data Structures
Prof. Neeraj Bhargava
Kapil Chauhan
Department of Computer Science
School of Engineering & Systems Sciences
MDS University, Ajmer
2. Introduction
Quick sort is a fast sorting algorithm used to sort a list
of elements.
The quick sort algorithm attempts to separate the list
of elements into two parts and then sort each part
recursively.
3. Cont..
That means it use divide and conquer strategy.
In quick sort, the partition of the list is performed
based on the element called pivot.
4. Cont…
Here pivot element is one of the elements in the list.
The list is divided into two partitions such that "all
elements to the left of pivot are smaller than the
pivot and all elements to the right of pivot are
greater than or equal to the pivot".
5. Cont..
It is also called partition-exchange sort. This
algorithm divides the list into three main parts:
Elements less than the Pivot element
Pivot element(Central element)
Elements greater than the pivot element
7. Algorithm
Step 1 − Choose the highest index value has pivot
Step 2 − Take two variables to point left and right of the list
excluding pivot
Step 3 − left points to the low index
Step 4 − right points to the high
Step 5 − while value at left is less than pivot move right
Step 6 − while value at right is greater than pivot move left
Step 7 − if both step 5 and step 6 does not match swap left
and right
Step 8 − if left ≥ right, the point where they met is new
pivot