Data Structure Using C Quick Sort: UNIT 2 - Searching and Sorting
Data Structure Using C Quick Sort: UNIT 2 - Searching and Sorting
Prepared By
Harshala Date
Sr. Lecturer
Department Of Computer Engineering
Unit Outcomes
A large array is partitioned into two arrays one of which holds values
smaller than the specified value, say pivot, based on which the
partition is made and another array holds values greater than the pivot
value.
For example
1 4 2 8 44 67 20 34
Working of Quick Sort(Partition-Exchange)
Step 4 − Repeat step 2 &3 until a & b are crossed or at same position.
Step 8 − End
8 4 2 67 44 1 20 34
Quick Sort
1 4 2 8 44 67 20 34
Quick Sort
1 * = 0th a=1st b= (n-1)th
Pass 2 – 2 a >= * b<*
if a=b OR cross
swap b & *
1 4 2 8 44 67 20 34 3
else
swap a & b
1 4 2 8 44 34 20 67
1 4 2 8 20 34 44 67
Quick Sort
1 * = 0th a=1st b= (n-1)th
Pass 3 -
2 a >= * b<*
if a=b OR cross
1 4 2 8 20 34 44 67
swap b & *
3
else
swap a & b
1 2 4 8 20 34 44 67
1 2 4 8 20 34 44 67
Time Complexity
On the average it runs very fast, even faster than Merge Sort.
It is not stable.
Sorting Techniques Time Complexity
.