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

Algorithm yields incorrect results #5

Open
maja42 opened this issue May 21, 2020 · 1 comment
Open

Algorithm yields incorrect results #5

maja42 opened this issue May 21, 2020 · 1 comment

Comments

@maja42
Copy link

maja42 commented May 21, 2020

The following input data:

arr := []int{65, 28, 59, 33, 21, 56, 22, 95, 50, 12, 90, 53, 28, 77, 39}
pivot := 8
_ = quickselect.IntQuickSelect(arr, pivot)

reorders the data to the following:

[28 33 21 22 50 12 28 39 *59* 56 90 53 65 77 95]

As you can see, the value at index 8 (59) is higher than the 56 at index 9.

A correct example would be:

[21 12 22 33 28 28 39 50 53 56 59 65 90 77 95]

(as produces by https://github.com/keegancsmith/nth)

@pracj3am
Copy link

This isn't a bug. Quickselect just selects 8 smallest elements and it does not guarantee anything about element at index 8.

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

No branches or pull requests

2 participants