C How to Program (8th Edition)
C How to Program (8th Edition)
8th Edition
ISBN: 9780133976892
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter D, Problem D.7E

(Quicksort) In the examples and exercises of Chapter 6 and this appendix, we discussed various sorting techniques. We now present the recursive sorting technique called Quicksort. The basic algorithm for a one-dimensional array of values is as follows:

  1. Partitioning Step: Take the first element of the unsorted array and determine its final location in the sorted array (i.e., all values to the left of the element in the array are less than the element, and all values to the right of the element in the array are greater than the element). We now have one element in its proper location and two unsorted subarrays.
  2. Recursive Step: Perform Step a on each unsorted subarray.

Each time Step a is performed on a subarray, another element is placed in its final location of the sorted array, and two unsorted subarrays are created. When a subarray consists of one element, it must be sorted; therefore, that element is in its final location.

The basic algorithm seems simple enough, but how do we determine the final position of the first element of each subarray? As an example? Consider the following set of values (the element in bold is the partitioning element—it will be placed in its final location in the sorted array):

Chapter D, Problem D.7E, (Quicksort) In the examples and exercises of Chapter 6 and this appendix, we discussed various , example  1

  1. Starting from the rightmost element of the array, compare each element with 37 until an element less than 37 is found. Then swap 37 and that element. The first element less than 37 is 12, so 37 and are swapped. The new array is
  2. Chapter D, Problem D.7E, (Quicksort) In the examples and exercises of Chapter 6 and this appendix, we discussed various , example  2

  3. Element 12 is in italic to indicate that it was just swapped with 37.
  4. 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 found. Then swap 37 and that element. The first element greater than 37 is 89, so 37 and 89 are swapped. The new array is
  5. Chapter D, Problem D.7E, (Quicksort) In the examples and exercises of Chapter 6 and this appendix, we discussed various , example  3

  6. Starting from the right, but beginning with the element before 89, compare each element with 37 until an element less than 37 is found. Then swap 37 and that element. The first element less than 37 is 10, so 37 and 10 are swapped. The new array is
  7. Chapter D, Problem D.7E, (Quicksort) In the examples and exercises of Chapter 6 and this appendix, we discussed various , example  4

  8. Starting from the left, but beginning with the element after 10, compare each element with 37 until an element greater than 37 is found. Then swap 37 and that element. There are no more elements greater than 37, so when we compare 37 with itself, we know that 37 has been placed in its final location in the sorted array.

Once the partition has been applied to the array, there are two unsorted subarrays. The subarray with values less than 37 contains 12, 2, 6, 4, 10 and s. The subarray with values greater than 37 contains 89, 63 and 45. The sort continues by partitioning both subarrays in the same manner as the original array.

Write recursive function quicksort to sort a one-dimensional integer array. The function should receive as arguments an integer array, a starting subscript and an ending subscript. Function partition should be called by quicksort to perform the partitioning step.

Blurred answer
Students have asked these similar questions
4. CodeW X For func X C Solved b Answer x+ https://codeworkou... ... [+) CodeWorkout X271: Recursion Programming Exercises: Minimum of array For function recursiveMin, write the missing part of the recursive call. This function should return the minimum element in an array of integers. You should assume that recursiveMin is initially called with startIndex = 0. Examples: recursiveMin({2, 4, 8}, 0) -> 2 Your Answer: 1 public int recursiveMin(int numbers[], int startIndex) { numbers.length - 1) { if (startIndex 2. return numbers[startIndex]; } else { return Math. min(numbers[startIndex], >); 5. { 1:11 AM 50°F Clear 12/4/2021
(Bubble Sort) Implement the bubble sort—another simple, yet inefficient, sorting technique. It’s called bubble sort or sinking sort because smaller values gradually “bubble” their way to the top of the array (i.e., toward the first element) like air bubbles rising in water, while the larger values sink to the bottom (end) of the array. The technique uses nested loops to make several passes through the array. Each pass compares successive overlapping pairs of elements (i.e., elements 0 and 1, 1 and 2, 2 and 3, etc.). If a pair is in increasing order (or the values are equal), the bubble sort leaves the values as they are. If a pair is in decreasing order, the bubble sort swaps their values in the array. The first pass compares the first two elements of the array and swaps them if necessary. It then compares the second and third elements. The end of this pass compares the last two elements in the array and swaps them if necessary. After one pass, the largest element will be in the last…
Exercise 2. (Pascal's Triangle) Pascal's triangle Pn is a triangular array with n+1 rows, each listing the coefficients of the binomial expansion (x+ y)', where 0 _ "/workspace/project3 рython3 pавса1.ру 10 1 1 1 1 2 1 1 33 1 1 4 6 4 1 1 5 10 10 5 1 16 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1 1 10 45 120 210 252 210 120 45 10 1 В равса1.ру import stdarray import stdio іпрort вys # Accept n (int) as command -line argument. ... # Setup a 2D ragged list a of integers. The list must have n + 1 rovs, vith the ith (0 <= i # <= n) row a[i] having i + 1 elements , each initialized to 1. For example, if n = 3, a should be # initialized to [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]. a =... for i in range (...): ... # Fill the ragged list a using the formula for Pascal's triangle 1] [j - 1) + a[i - 1] [j] a [i][j] = a[i - 1] [j - 1] + a[i - 1] [j] #3 # vhere o <- i <- n and 1 <= j < i. for i in range (...): for j in range (...): ... # Write a to standard…

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
How is a constructor named?

Starting Out with Java: Early Objects (6th Edition)

Hotel Occupancy A hotels occupancy rate is calculated as follows: Occupancyrate=NumberofroomsoccupiedTotalnumbe...

Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)

Design a sequence of steps that correctly interchanges the contents of these cells. If needed, you may use addi...

Computer Science: An Overview (13th Edition) (What's New in Computer Science)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation; Author: Jenny's lectures CS/IT NET&JRF;https://www.youtube.com/watch?v=AT14lCXuMKI;License: Standard YouTube License, CC-BY
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License