Question

In: Computer Science

use quick sort to sort the following array. show each pass and what the pivot is...

use quick sort to sort the following array. show each pass and what the pivot is during the pass. please explain why you are swapping positions. do not use a compiler.

30 5 40 11 20 9 15 2 60 25 80 3 73 35 4 75 20 6

Solutions

Expert Solution

[30 5 40 11 20 9 15 2 60 25 80 3 73 35 4 75 20 6]
pivot = 6
after partition->
[5 2 3 4] 6 [9 15 30 60 25 80 40 73 35 11 75 20 20]

[5 2 3 4]->
pivot = 4
after partition->
[2 3] 4 [5]
after rcursive call on [2 3]
[2][3]

[9 15 30 60 25 80 40 73 35 11 75 20 20]->
pivot = 20
after partition->
[9 15 11] 20 [30 80 40 73 35 25 75 20]

[9 15 11]->
pivot = 11
[9] 11 [15]

[30 80 40 73 35 25 75 20]->
pivot = 20
after partition->
20 [80 40 73 35 25 75 30]

[80 40 73 35 25 75 30]->
pivot = 30
after partition->
[25] 30 [73 35 80 75 40]

[73 35 80 75 40]->
pivot = 40
after partition->
35 40 [80 75 73]

[80 75 73]->
pivot = 73
73 [75 80]

[75 80] ->
pivot = 80
[75] 80


Related Solutions

Write a program in Java to sort the given array using merge sort, quick sort, insertion...
Write a program in Java to sort the given array using merge sort, quick sort, insertion sort, selection sort and bubble sort based on the input from the user which sorting technique they wanted to use. Get the array size, array elements from the user, and also display the sorted array along with the name of the sorting technique used.
Quick Sort as explained in class uses a Pivot value to arrangeall numbers greater than...
Quick Sort as explained in class uses a Pivot value to arrange all numbers greater than the pivot on oneside and all values smaller than the pivot on the other side. Pivot in the class example used the firstelement of the array. “Median of three” rule uses the median of the first last and the middle elementsof the array as the Pivot so that we avoid the chance of picking the smallest or the largest element in thearray.a) Write the...
What is the runtime for quick sort?
What is the runtime for quick sort?
For the given array, simulate the working operation of Bubble Sort. Show your work at each...
For the given array, simulate the working operation of Bubble Sort. Show your work at each step. Make sure to show the status of the array after every swap. [ 28, 13, 22, 7, 34, 2 ]
One way to improve quick sort is to use an insertion sort on lists that have...
One way to improve quick sort is to use an insertion sort on lists that have a small length (call it the “partition limit”). Why does this make sense?
(Data structure) Show the contents of the array below, once the “pivot” element is placed at...
(Data structure) Show the contents of the array below, once the “pivot” element is placed at its appropriate location after each call of the “Partition” algorithm, in the process of running Quick-Sort on said array. Arrange the data in descending order (from largest to smallest value). Always select the first element of the partition as “pivot” Apply sorting on the following data set s,       f,       p,      a,      g,      e,       v,      q,      i,        c
Given the following array [17, 15,21,208,16,122,212,53,119,43] Apply bubble sort algorithm and show the status of the...
Given the following array [17, 15,21,208,16,122,212,53,119,43] Apply bubble sort algorithm and show the status of the array after each pass. Also calculate how many comparisons you will be required to pass
Which of the following sorting algorithms are stable: insertion sort, selection sort, merge sort and quick...
Which of the following sorting algorithms are stable: insertion sort, selection sort, merge sort and quick sort? Give a simple scheme that makes any sorting algorithm stable. How much additional time and space does your scheme entail?
Given the following array, write a program in C++ to sort the array using a selection...
Given the following array, write a program in C++ to sort the array using a selection sort and display the number of scores that are less than 500 and those greater than 500. Scores[0] = 198 Scores[3] = 85 Scores[6] = 73 Scores[9] = 989 Scores[1] = 486 Scores[4] = 216 Scores[7] = 319 Scores[2] = 651 Scores[5] = 912 Scores[8] = 846
Sort the following set of numbers using bubble sort, insertion sort, and selection sort. Show the...
Sort the following set of numbers using bubble sort, insertion sort, and selection sort. Show the process step-by-step, and find the time complexity in Big-O notation for each method. For sorting, use ascending order. 49, 7, 60, 44, 18, 105
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT