0% found this document useful (0 votes)
56 views1 page

Quick Sort

Quick sort is a sorting algorithm that works by partitioning an array around a pivot value and calling itself recursively to sort the sub-arrays on either side of the pivot. It first partitions the array by choosing a pivot value and swapping values around it such that all values less than the pivot come before values greater than the pivot. It then recursively calls itself on the sub-arrays to complete the sorting.

Uploaded by

Saurav Naruka
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views1 page

Quick Sort

Quick sort is a sorting algorithm that works by partitioning an array around a pivot value and calling itself recursively to sort the sub-arrays on either side of the pivot. It first partitions the array by choosing a pivot value and swapping values around it such that all values less than the pivot come before values greater than the pivot. It then recursively calls itself on the sub-arrays to complete the sorting.

Uploaded by

Saurav Naruka
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

www.eazynotes.

com

Gursharan Singh Tatla

Page No. 1

QUICK SORT
Quick Sort ( A, BEG, END ):
Description: Here A is an unsorted array. BEG is the lower bound and END is the upper bound. 1. 2. 3. 4. 5. Exit If (BEG < END) Then X = Partition (A, BEG, END) Call Quick Sort (A, BEG, X 1) Call Quick Sort (A, X + 1, END) [End of If]

Partition ( A, BEG, END )


Description: Here A is an unsorted array. BEG is the lower bound, END is the upper bound. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. Exit Set LOC = BEG Repeat While (True) Repeat While (A[LOC] <= A[END]) and (LOC != END) END = END 1 [End of While Loop] If (LOC == END) Then Return LOC [End of If] Interchange A[LOC] and A[END] Set LOC = END Repeat While (A[LOC] >= A[BEG]) and (LOC != BEG) BEG = BEG + 1 [End of While Loop] If (LOC == BEG) Then Return LOC [End of If] Interchange A[LOC] and A[BEG] Set LOC = BEG [End of While Loop]

You might also like