edited by
1,098 views
0 0 votes
13, 60,19,52,45,27,41,30,34,32.. Is this sequence in an array a worst case for Quicksort if first element is choosen as pivot always?

I have tried to run algorithm of Quicksort on this sequence but not getting it.. Can anyone please explain this?

 

My approach is::

After 1st iteration array is splitted into(pivot is 13):

sub-array1:: null

subarray 2:: 60,19,52,45,27,41,30,34,32

 

applying quicksort on subarray 2:

After 2nd iteration sub-array 2 is splitted into(pivot is 60):

sub-array 21:: 32,19,52,45,27,41,30,34

sub-array 22:: 60

 

applying quicksort on subarray 22(pivot is 32):

After 3rd iteration sub-array 22 is splitted into:

sub-array 221:: 30,19,27

sub-array 223:: 52,41,45,34

 

and seeing this iteration 3 we can say this is not a worst case hence for whole array it would not be a worst of if sorting using Quicksort..

 

Can someone please tell me where I am thinking wrong??

1 Answer

2 2 votes

No, Nothing can be said.

beause worst cases, best cases can be observed only for n length arrays. You can notice if we will try to see number of time pivot choosen here, if you will see carefully it can be said as n/Constant as well as it can also be said as only some constant times pivot has been selected. So saying anything would be wrong without observing pattern for n length Arrays.

“If Partition algorithm is doing only 1 partition of array for Asymptotically n times then it’ll be considered as worst case scenerio.”

also by default the pivot choosen is left most in the default QuickSort Algorithm.

 
 
 
edited by
Position:
Show:

Related questions

1 1 vote
1 1 answer
132
132 views
GO Classes asked Aug 31
132 views
During sorting, one complete processing of all elements whose final positions have not yet been determined is called a pass.Which of the following sequences cannot be the...
0 0 votes
1 1 answer
111
111 views
GO Classes asked Aug 10
111 views
Consider the Quick sort algorithm which sorts elements in ascending order using the first element as pivot. Then which of the following input sequence will require a maxi...
0 0 votes
1 1 answer
154
154 views
Udit_goyal asked May 6
154 views
1. what is the space Complexity of efficient Quick sort algorithem for best case ? in a lecture Reddy Sir Said that it is O(1) is this correct  2.if in the gate exam if t...
0 0 votes
1 1 answer
672
672 views
dharmik_3103 asked Dec 5, 2024
672 views
In quick sorting algorithm 2 elements i and j are compared if and only if among all the elements, the element to be picked as pivot is either i or j. Is this statement tr...