Given $n$ entries, I uniformly sample $b$ entries without replacement among them.
My question is that I want a very fast algorithm to do such things, and what is its time complexity? Is the constant in the time complexity $O()$ big?
Given $n$ entries, I uniformly sample $b$ entries without replacement among them.
My question is that I want a very fast algorithm to do such things, and what is its time complexity? Is the constant in the time complexity $O()$ big?
Copyright © 2021 JogjaFile Inc.
I'm sure your question has been thoroughly researched and published (did you google it?). I haven't personally needed exactly what you're asking for, but I have needed random permutations of $1\ldots n$, for which I wrote the following little function, based on googling the algorithm it implements...
Now, I think you'd just want the first $b<n$ entries, taking $p[0]\ldots p[b-1]$ as your random sample without replacement. And in that case, I think you could just stop the loop at $b-1$ (instead of at $n-1$ for the entire permutation). And then the complexity's clearly just linear in $b$, which I suppose is pretty much as good as you can hope for.