Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All, I am trying to use quicksort and I have a question say i got an array 5 8 1 2 6 and I chose 1 as pivot then there are no elements less than Pivot to swap .. so how will my iteration turn into .. !

What I have tried:

understanding quicksort, i understand that lowest number shouldn't be chosen as Pivot as it will take n2 but if i am tryng to understand what happens if the pivot is actually 1.
Posted
Updated 29-Nov-18 8:25am

Run the code through your debugger and you will see exactly what happens.
 
Share this answer
 
Quote:
Quicksort help if the pivot chosen is least i.e 1

Even if pivot is lowest value, everything works the same.
A poor choice of pivot is just unfortunate and will be simply less efficient than a pivot than is in middle of values, its the only difference.
Quicksort - Wikipedia[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900