930 views

1 Answer

1 votes
1 votes

If you observe PARTITION of the array algorithm carefully then you'll observe at line 4 i.e. in 

$if   A[j]\leq x$

simply the change it to $\leqslant$ which is

$if A[j]\geqslant x$

this will make all the elements greater than pivot move to the left of the array and rest to the right which is the desired result.

Related questions

0 votes
0 votes
1 answer
1
akash.dinkar12 asked Jun 27, 2019
1,461 views
Give a brief argument that the running time of PARTITION on a subarray of size $n$ is $\Theta(n)$.
0 votes
0 votes
1 answer
2
akash.dinkar12 asked Jun 27, 2019
1,707 views
What value of $q$ does PARTITION return when all elements in the array $A[p..r]$ have the same value? Modify PARTITION so that $q=\lfloor(p+r)/2 \rfloor$ when all element...