Skip to content

Commit

Permalink
Update README.markdown
Browse files Browse the repository at this point in the history
when k > n/2 ,  we just need random select a.count - k elements and remove them from the original array
  • Loading branch information
KeithMorning authored Jan 31, 2018
1 parent e14a46f commit 5beb84a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Selection Sampling/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ print(output.count)

The performance of this second algorithm is **O(n)** as it may require a pass through the entire input array.

> **Note:** If `k > n/2`, then it's more efficient to do it the other way around and choose `k` items to remove.
> **Note:** If `k > n/2`, then it's more efficient to do it the other way around and choose `a.count - k` items to remove.
Based on code from Algorithm Alley, Dr. Dobb's Magazine, October 1993.

Expand Down

0 comments on commit 5beb84a

Please sign in to comment.