Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is an Data Strucrutre and Algorithms class. Show complete steps. Question:

ID: 3878027 • Letter: T

Question

This is an Data Strucrutre and Algorithms class.

Show complete steps.

Question:

There are 8 comparisons suffice to sort an array of 5 keys (a key will be for us an arbitrary real number) using the result for 4 keys and inserting the lone fifth key into the sorted 4-array. Modify the argument to show that 7 comparisons are enough to sort that array of 5 keys. Use diagrams with dotted lines (comparisons) and vertical lines between keys (the higher is the smaller) to show the orders of the keys after comparisons.

Explanation / Answer

Demand of the question is to solve an array of 5 keys by using any sorting algorithm.

Let us take an array with the following elements 15,10,8,5,20.

Apply Quicksort on the above given array.

In quick sort algorithm, we need to take an pivot element and then sort the list accordingly.

Now, take 15 as the pivot element. And compare 15 with 10, as 10<15 then pivot will move to the right.. Now compare 15 with 8. Same like last 8<15. Now, we have to move again to the right again 5<15 and move to the right. Now, 15 is less than 20 here. 20>15.

Now the list will be sorted as

5,10,8,15,20.

------------------------------------------------------------------------------------------------------------------------------------------

Now list is partitioned into two parts, 1st part is before the pivot element means before 15 and other part is at the last of the pivot element.

1st list to sort 5,10,8

15

Last list after pivot element 20

---------------------------------------------------------------------------------------------------------------------------------------------------------

Now 5 is the pivot element, now need to set the position of the pivot element in the first list means 5,10,8. compare 5 with 10. Here 5<10. Furthermore, 5 < 8. So, no need to change the position of the pivot element

List after sorting pivot element 5.

Sorted pivot element 5

Unsorted list - 10,8

Another pivot 15

Another sorted list 20

---------------------------------------------------------------------------------------------------------------------------------------------------------

Now, need to sort the last unsorted list. Unsorted list is 10, 8. Here, pivot is 10. compare 10 with 8. As 10>8 then exchange the position of 10 by the position of 8 by 10.

List sub-lists are-

5

8

10

15

20

--------------------------------------------------------------------------------------------------------------------------------------------------------

Now last step is to merge all these sub-lists. After merging the sub-lists, the sorted list will be 5,8,10,15,20.

Hence the list is sorted.

5,8,10,15,20.

---------------------------------------------------------------------------------------------------------------------------------------------------------

Time complexity of quicksort is n * log n.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote