fixed quicksort partition and secondsmallest function #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://donsheehy.github.io/datastructures/fullbook.html#quicksort
The version without all comments looks like has some problem in last two lines
#Put the pivot in place.
L[pivot], L[i] = L[i], L[pivot]
return i
I think we still need to compare L[pivot] with L[i].
An example case is [1,2]. If we directly swap them, the result will be [2,1].
https://donsheehy.github.io/datastructures/fullbook.html#selection
It looks like there is a typo in the secondsmallest function
def secondsmallest(L):
a, b = None, None
for item in L:
if a is None or item <= b: # it should be item <=a I guess
a, b = item, a
elif b is None or item <= a: # it should be item <= b I guess
b = item
return b
https://donsheehy.github.io/datastructures/fullbook.html#the-quickselect-algorithm
The quick selection uses the partition function. I think we still need to compare compare L[pivot] with L[i] to decide whether to swap them or not.