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

Correct interval notation #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions quickselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ package quickselect

import (
"math/rand"
"errors"
"fmt"
"container/heap"
)
Expand Down Expand Up @@ -298,14 +297,13 @@ QuickSelect implements Hoare's Selection Algorithm and runs in O(n) time, so it
is asymptotically faster than sorting or other heap-like implementations for
finding the smallest k elements in a data structure.

Note that k must be in the range [0, data.Len()), otherwise the QuickSelect
Note that k must be in the range (0, data.Len()], otherwise the QuickSelect
method will raise an error.
*/
func QuickSelect(data Interface, k int) (error) {
length := data.Len()
if (k < 1 || k > length) {
message := fmt.Sprintf("The specified index '%d' is outside of the data's range of indices [0,%d)", k, length)
return errors.New(message)
return fmt.Errorf("The specified index '%d' is outside of the data's range of indices (0,%d]", k, length)
}

kRatio := float64(k) / float64(length)
Expand Down