Question

Perform the partition method of quick sort once on the array [8, 12, 2, 15, 7]....

Perform the partition method of quick sort once on the array [8, 12, 2, 15, 7]. Show the array after each iteration of the while loop in the partition method. Use the first element (here it is 8) as the pivot. Show the two-sub array after one call to quick sort.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

INPUT ARRAY : 8, 12, 2, 15, 7

#1: PIVOT : 8

8, 7, 2, 15, 12

moving pivot to correct position : 2, 7, 8, 15, 12

PARTITIONS: [2, 7] and [15,12]

#2 PIVOT1 for partition 1 : 2   #2 PIVOT2 for partition 1 : 15
partition becomes : 2, 7   partition becomes : 15, 12

moving pivot : 2, 7 moving pivot: 12, 15

Now joining results : [2,7] [8] [12,15]

sorted array : 2, 7, 8, 12 ,15

Time complexity : O(n logn)

Add a comment
Know the answer?
Add Answer to:
Perform the partition method of quick sort once on the array [8, 12, 2, 15, 7]....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Sorting Sort the following array using the quick sort algorithm: (4 Marks) a. 12 26 8...

    Sorting Sort the following array using the quick sort algorithm: (4 Marks) a. 12 26 8 9 7 0 4 Pivot selection is defined to be the first element of each sub-list. Show the array before and after each quicksort round (when the array is partitioned after placing the pivot at its correct position). Also, clearly highlight the pivot in each partition b. Consider an unsorted array of integers of size n. Write a Java program to arrange the array...

  • Show the contents of the array below, once the “pivot” element is placed at its appropriate...

    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 ascending order (from smallest to largest value). Always select the first element of the partition as “pivot” Apply sorting on the following data set 19,       20,       1,         13,       16,       5,         4,         9,         14,       7 Index 0 1 2 3 4 5 6 7...

  • _______________________________________________________________________________________________ java language-trace instructions". (20 points) Show the contents of the array below, once the contents...

    _______________________________________________________________________________________________ java language-trace instructions". (20 points) Show the contents of the array below, once the contents of the array below, once the "pivot" element is placed at its location after each call of the "Partition” algorithm, in the process of running Quick-Sort on said array. Arrange the data in ascending order (Trom Arrange the data in ascending order (from smallest to largest value). Always select the first element of the partition as "pivot" in data cat B. Apply sorting on...

  • JAVA- Trace the recursive quick sort and partition methods in Lab6.java for this list of numbers:...

    JAVA- Trace the recursive quick sort and partition methods in Lab6.java for this list of numbers: 47 71 15 35 66 61 44 26 68 56 18 19 36 84 69 55 1. Find the value of pivot 2. Show the result after partitionIt() is called first time 3. Show the value of partition 4. Show the content of the array ///////////////////////////// Lab6.java class ArrayIns { private long[] theArray; // ref to array theArray private int nElems; // number of...

  • 8. Related to the merge sort is an efficient procedure called quick sort. Here we start...

    8. Related to the merge sort is an efficient procedure called quick sort. Here we start with a list L : a,a2,, an, and use a as a pivot to develop two sublists L and L2 as follows. For i > 1, if aa, place a at the end of the first list being developed (which is L1 at the end the process); otherwise, place a at the end of L2. After all a,, i >1, have been processed, place...

  • Assume that you are sorting an array of 8 elements with quick sort. You just finished...

    Assume that you are sorting an array of 8 elements with quick sort. You just finished the first pass and the array looks like below. Which statement is true for the pivot value? 4 8 12 16 18 20 22 24 QUICKSORT ALGORITHM Quicksort selects a specific value called a pivot and rearranges the array into two parts (called partioning). If the array is randomly ordered, it does not matter which element is the pivot. For simplicity, the first element...

  • [6 marks] Suppose we run three sorting methods on copies of an array containing 1, 7,...

    [6 marks] Suppose we run three sorting methods on copies of an array containing 1, 7, 19, 24, 7, 49 (in that order). Suppose we stop each method before it is complete (as described below). In each case, give the order of the values as they would appear in the array after we stopped each sort. a. Quick sort (that uses the median-of-three technique to find its pivot) stopped IMMEDIATELY BEFORE the first recursive call starts. b. Radix sort stopped...

  • Using C++, sort an array of 10,000 elements using the quick sort algorithm as follows: a....

    Using C++, sort an array of 10,000 elements using the quick sort algorithm as follows: a. Sort the array using pivot as the middle element of the array. b. Sort the array using pivot as the median of the first, last, and middle elements of the array. c. Sort the array using pivot as the middle element of the array. However, when the size of any sublist reduces to less than 20, sort thesublis t using an insertion sort. d....

  • Java 1. (5) Assume selection sort is applied to the following array. Show the state of...

    Java 1. (5) Assume selection sort is applied to the following array. Show the state of the array after the first pass of the outer loop. 50 35 15 100 90 20 10 25 2. (5) Assume bubble sort is applied to the following array. Show the state of the array after the first pass of the outer loop 50 35 15 100 90 20 10 25 3. (5) Assume quicksort is applied to the following array. Show the state...

  • [5 marks] Using selection sort algorithm to sort the array int array[7]-5, 6, 2, 7, 9,...

    [5 marks] Using selection sort algorithm to sort the array int array[7]-5, 6, 2, 7, 9, 4, 3). Assuming we call the following function using statement selection sort (int array, 7); Please fill the table to show the changes of the array int_array after each iteration. The first column is filled. void selection_sort (int list[], int list_size) for (int i = 0; i < list size - 1; 1++) int current min = list[1]; int current_min_index-i for (int j -...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT