Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ RECURSION C++ Recursion (Quicksort) The recursive sorting technique called quicksort uses the following basic algorithm for a one-dmensional array of values: Partitioning Step: Take
C++ RECURSION
C++ Recursion (Quicksort) The recursive sorting technique called quicksort uses the following basic algorithm for a one-dmensional array of values: Partitioning Step: Take the tirst element ot the unsorted array and determine its tinal location in the sorted array (ie, al values to the left of the element in the array are less than the element's value, and all values to the right of the element in the array are greater than the element's value-we show how to do this below). We now have one value in its proper kcation and two unsorted sub-arrays. Recursion Step; Perform the Partitioning Step ?n cach unsorted sub-array Each time Siep 1 is performed on a sub-array, another element is placed in its final location of the sorted array, and two unsorted sub-arrays are created. When a sub-array consists of one element, that sub-array must be sorted; theretore, that element is in its tinal location. The basic algorithm seems simple enough, but how do we determine the final position of the first element of each sub-array? As an example, cons der the following set of values (the element in bold is the partitioning element-it will be placed in its final location in the sorled 37 2 6 4 89 8 10 12 68 45 Starting from the rightmost element of the array, compare each element with 37 until an element less than 37 is tound. Then swap 37 and that element. The first element less than 37 is 12, so 37 and 12 are swapped. The values now reside in the array as follows: 12 26 4 89 8 10 37 6845 Element 12 is in italics to indicate that it was just swapped with 37 Starting from the left of the array, but beginning with the element after 12, compare each element with 37 until an element greater than 37 is tound. Then swap 37 and that element. The first element greater than 37 is 89, so 37 and 89 are swapped. The values now reside in the array as tolows: 12 2 6 4 37 8 10 89 68 45 7:42 AM 4/19/2018 Type here to searchStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started