Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed quicksort partition and secondsmallest function #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

qyynuaa
Copy link

@qyynuaa qyynuaa commented Mar 25, 2019

  1. 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].

  2. 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

  3. 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.

@ziqiyang107
Copy link

quick selection code doesn't work sometimes, need to fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants