This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full 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 subarray is larger than any element in the last subarray. i.e., all elements in the first subarray are smaller or equals to a pivot value, and all elements in the last subarray 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 subarray contains elements smaller or equals to 5, and the second subarray contains elements greater or equals to 5. We can repeat the similar partitioning process on two sub arrays (to get four subarrays, and so on). At the end, we will have a sorted array. //The quickSort method calls partition method to partition...
View Full
Document
 Spring '10
 Nakamura

Click to edit the document details