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 MIPS program that uses an implementation of quick sort to sort an array of...
Write a MIPS program that uses an implementation of quick sort to sort an array of numbers (Translate the following code into (Mars Assembly language). Quicksort Implementation - C int partition(int arr [] , int left , int right) { int i=left, j=right; int tmp; int pivot = arr[(left + right) / 2]; while (i <= j) { while (arr [ i ] < pivot) i ++; while (arr [ j ] > pivot) j −−; if (i <= j)...
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?
6. The worst case scenario in the quick sort occurs when the array is partitioned to...
6. The worst case scenario in the quick sort occurs when the array is partitioned to two equal sized subarray every time that a recursive call takes place. True False 7.Suppose that we want to sort an array of n elements, where each element is a string of at most 1000 characters. What is the time requirement for applying radix sort to sort this array? O(n2) O(1000n) O(l000logn) O(nlogn) 8.Suppose we want to sort the following array of integers using...
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
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 [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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT