QuickSort

QuickSort - Quick Sort algorithm The quick sort uses the...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Quick Sort algorithm The quick sort uses the strategy of divide and conquer like merge sort. Its idea is to rearrange the element in the range so that no element in the first sub-array is larger than any element in the last sub-array. i.e., all elements in the first sub-array are smaller or equals to a pivot value, and all elements in the last sub-array are greater or equals to a pivot value. There are several ways to pick a pivot value, but one way is to pick the first element of a given array. If we have an array containing: {5 3 2 6 4 1 3 7} And if we use 5 (the first element of this array) as a pivot to partition, we can arrange it into two sub arrays as: {3 3 2 1 4} {6 5 7} (this can be viewed as one array { 3 3 2 1 4 6 5 7 }) The first sub-array contains elements smaller or equals to 5, and the second sub-array contains elements greater or equals to 5. We can repeat the similar partitioning process on two sub arrays (to get four sub-arrays, and so on). At the end, we will have a sorted array. //The quickSort method calls partition method to partition...
View Full Document

Page1 / 4

QuickSort - Quick Sort algorithm The quick sort uses the...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online