Question

In: Computer Science

Compute the first 4 pivots using quick sort algorithm on an array A=<10,15,17,18,6,120,30,250,95>. Write the content...

Compute the first 4 pivots using quick sort algorithm on an array A=<10,15,17,18,6,120,30,250,95>. Write the content of the array A after each pivot is chosen.

Solutions

Expert Solution

In case of any queries, please revert back. I will solve them ASAP.

A={10,15,17,18,6,120,30,250,95}

Lets say we always choose the last element as the pivot.

What are the steps?

1. Choose Pivot

2. All elements smaller than pivot are left to pivot.

3. All elements larger than the pivot are right to pivot.

4. Repeat for left and right half

Order of elements does not change.

============== 1ST PIVOT =================

Pivot Chosen is 95 ie last element.

A = {10,15,17,18,6,30,95,120,250}

This is the array after the first pivot.

============== 2ND PIVOT =================

Pivot Chosen is 30 ie last element of left part!

A = {10,15,17,18,6,30,95,120,250}

This is the array after the second pivot. 30 was at the correct position.

=============== 3RD PIVOT ===================

Pivot Chosen is 6 ie last element of left part of 30.

A = {6,10,15,17,18,30,95,120,250}

This is the array after the third pivot. Here 6 was smallest so all elements moved to right.

==============4th PIVOT =====================

Now 6 has not left part. So we start with right part to move up the recursion. So, Pivot choosen is 18.

A = {6,10,15,17,18,30,95,120,250}

This is the array after the fourth pivot. 18 was at the correct postion as there is no greater element than 18.

If we move forward we see that 17,15 and 10 are at the correct positon! These will be 5th,6th and 7th pivot.

A = {6,10,15,17,18,30,95,120,250}

Now, recursion moves forward and checks right of 95.

So, 120 and 250 are at correct position

A = {6,10,15,17,18,30,95,120,250}


Related Solutions

Sorting (quick) Sort the array using quick sort. Write the array content after each pass (i.e.,...
Sorting (quick) Sort the array using quick sort. Write the array content after each pass (i.e., from pass 1 to pass 7). Each pass is defined as the completion of one partition. We always pick the first array element as the pivot for each partition.
Sorting (merge) Sort the array (as in Part 2) using merge sort. Write the array content...
Sorting (merge) Sort the array (as in Part 2) using merge sort. Write the array content after each pass (i.e., from pass 1 to pass 9). Each pass is defined as the completion of one merge operation. Suppose an array contains the following integers: -1, 20, 10, -5, 0, -7, 100, -7, 30, -10. Sort the array using the following algorithms: selection sort, bubble sort, and insertion sort. For each algorithm, write the array content after each pass (i.e., from...
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.
Q1) Write a program to implement the quick sort algorithm in a one dimensional array? Q2)...
Q1) Write a program to implement the quick sort algorithm in a one dimensional array? Q2) Write a program to implement the merge sort algorithm in a one dimensional array?
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)...
●In this task, the quick sort algorithm selects the first element in the list as the...
●In this task, the quick sort algorithm selects the first element in the list as the pivot. Revise it by selecting the median among the first, middle, and last elements in the list. ● Write the algorithm for searching for entries using linear probing. ● Write the algorithm for removing entries using linear probing. ● Create a diagram similar to the one above that shows the hash table of size 11 after entries with the keys 34, 29, 53, 44,...
1. Sort the given keys using Counting sort algorithm. Also write the algorithm.          4, 1,...
1. Sort the given keys using Counting sort algorithm. Also write the algorithm.          4, 1, 0, 2, 1, 5, 0, 4                                                                     No code or programs, please. Manually solve the problem, please. Thanks
please write a C program that implements Quick Sort algorithm.
please write a C program that implements Quick Sort algorithm.
Sort 33, 77, 22, 11, 34, 21, 88, 90, 42 using Quick sort. Write the algorithm....
Sort 33, 77, 22, 11, 34, 21, 88, 90, 42 using Quick sort. Write the algorithm. show work
Import a data set (txt file) then do the sorting algorithm using quick sort, shell sort,...
Import a data set (txt file) then do the sorting algorithm using quick sort, shell sort, and selection sort. It must show how long it took and how many movements occurred. Please write codes in C++ Here's data set (should be stored in txt file) 7426 4524 4737 9436 3997 2757 6288 5414 9590 5968 6638 3199 9514 1541 9866 2144 6731 911 2171 6135 6437 912 9417 2662 6606 6349 707 2890 5386 9718 3492 5068 9674 8578 8323...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT