Question: 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 C++ Recursion (Quicksort) The recursive sorting technique called quicksort usesthe following basic algorithm for a one-dmensional array of values: Partitioning Step:

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 search

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!