5 ms·
I may not have parsed your question correctly, so I apologize in advance. Assuming you are asking about what happens to the "equal" elements- Yes, there is a b
by cmurphycode 10y ago
I may not have parsed your question correctly, so I apologize in advance. Assuming you are asking about what happens to the "equal" elements-
Yes, there is a bug in this code. It doesn't handle repeated elements.
If you fix the code by including an equality in one of the two groups, then it works, but it degrades when there are many repeated elements. In the worst case, you can only shrink your groups by one each time, which means the complexity changes to O(n^2) :(
You can fix THIS issue using a 3-way partition. That is the algorithm I've used. With a good pivot choice (random or median of three), this gives you an in-place sort which is guaranteed to be O(nlgn). Nice!