Illustrate Quick Sort to sort the following dataYou need to

Illustrate Quick Sort to sort the following data.[You need to sort alphabetically. Assume that numerical value of the character according to their position in the alphabet, i.e. q = 17, U= 21, I = 9, C = 3, K = 11, S = 19, O = 15, R = 18}

Solution

Okay so let’s Start the Quick Sort Algorithm, we have 2 Parts in a Quicksort Algorithm

Partition:-We take the first or last element to be the pivot, and then compare each element from left or right with the pivot, if the element is smaller in Value than the pivot we keep the element in the left of the Pivot Element, and if the element which is being compared is greater than the pivot Element we keep it to the right of the pivot element.

Quicksort: - Quicksort sorts the elements to the left of the pivot and to the right of the pivot.

The Algorithm of the Partition and Quicksort is as given.

We have the Given Elements:-

Q=17

U=21

I=9

C=3

K=11

S=19

O=15

R=18

17,21,9,3,11,19,15,18

So let us take 18 to be the Pivot Element and start from the left side

So we get,

17,9,3,11,15,18,21,19

Now we got a Partition at the pivot element 18, no we have to parts 17,9,3,1,15 and 21,19

Apply partition on Both the Parts

Taking 15 to be Pivot in 1st Part

Taking 19 to be pivot in 2nd Part

We get 9,3,11,15,17 and 19,21(Sorted)

Now taking 2 parts of 9,3,11,15,17

Take 11 to be pivot we get 9,3,11, so 1 Part 9,3 So, take 3 to be Pivot we get 3,9

So we have 3,9 11 17 18 19,21

So, we get a Sorted array and the Final Sorted Array is 3,9,11,17,18,19,21

Thank You for using Chegg...

 Illustrate Quick Sort to sort the following data.[You need to sort alphabetically. Assume that numerical value of the character according to their position in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site