We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1
Algorithm Quicksort (arr, low, high)
Input: An array arr, and indices low and high defining the range to be sorted.
1. if low < high then
2. pivotIndex <- Partition(arr, low, high) // Partition the array and get the pivot index. 3. Quicksort(arr, low, pivotIndex - 1) // Recursively sort the left subarray. 4. Quicksort(arr, pivotIndex + 1, high) // Recursively sort the right subarray.
Algorithm Partition (arr, low, high)
Input: An array arr, and indices low and high defining the range to be partitioned.
1. pivot <- arr[high] // Choose the pivot as the last element.
2. i <- low - 1 // Initialize the index of the smaller element. 3. for j from low to high - 1 do 4. if arr[j] < pivot then 5. i <- i + 1 6. Swap arr[i] and arr[j] // Swap arr[i] and arr[j]. 7. Swap arr[i + 1] and arr[high] // Swap the pivot element with arr[i + 1]. 8. return i + 1 // Return the index of the pivot element.