Chapter 20: Problem 10
(Quicksort) The recursive sorting technique called quicksort uses the following basic algorithm for a one-dimensional vector of values: a. Partitioning Step : Take the first element of the unsorted vector and determine its final location in the sorted vector (i.e., all values to the left of the element in the vector are less than the element, and all values to the right of the element in the vector are greater than the elementwe show how to do this below). We now have one element in its proper location and two unsorted subvectors. b. Recursion Step : Perform Step 1 on each unsorted subvector. Each time Step 1 is performed on a subvector, another element is placed in its final location of the sorted vector, and two unsorted subvectors are created. When a subvector consists of one element, that element is in its final location (because a one-element vector is already sorted). The basic algorithm seems simple enough, but how do we determine the final position of the first element of each subvector? As an example, consider the following set of values (the element in bold is the partitioning elementit will be placed in its final location in the sorted vector): $$\begin{array}{llllllllll} 37 & 2 & 6 & 4 & 89 & 8 & 10 & 12 & 68 & 45 \end{array}$$
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.