Allow me to be more specific by using an example (in Java).
Say you want to sort this array:
[10, 20, 30, 40, 50, 60, 70, 80, 90]
Lets assume the pivot is, oh say, the value 30. After sorting it should look like this:
[40, 50, 60, 70, 80, 90, 30, 10, 20]
The numbers that are greater than 30, end on the left side of 30 (while still sorted as least to greatest) and the numbers less than 30 are on the right side of 30 (while still sorted as least to greatest).
Note: Assume that the data set is very large, it doesn't have to this exact array set.
Now here's my algorithm that I had come up with (in pseudocode):
1). Count how many values are more than 30, call this count value 'X'. Swap the value of 30 at index X.
2). Have 2 "movers" that start on both ends, each moving towards the pivot and determining which numbers should go on what side
3). Use bubble sort on both sides of the pivot to finish the algorithm.
Now, here's my problem with my own algorithm. It's O(n) up until I get to the bubble sort, which makes it O(n^2).
My specific question is: What would be a better approach for this and still keep it as O(n)? Or if possible O(log n) ? Answers could be in pseudocode, but you chose to code for the answer, I prefer it be in Java.
Note: The array is an integer array. All with unique values.
Edit: Mergesort is obviously a much better solution than bubble sort. My question is really geared towards finding an O(n) or O(log n) solution.