[Paper Review] Simple, Optimal Algorithms for Random Sampling Without Replacement
This paper presents simple, optimal algorithms for random sampling without replacement, achieving O(k) time and space complexity by using sparse hash tables to replace dense array initialization. It introduces novel methods like the Sparse Fisher-Yates and Beta-Binomial in-order sampling, which outperform classical approaches in efficiency and applicability across sequential, distributed, and streaming settings.
Consider the fundamental problem of drawing a simple random sample of size k without replacement from [n] := {1, . . . , n}. Although a number of classical algorithms exist for this problem, we construct algorithms that are even simpler, easier to implement, and have optimal space and time complexity.
Motivation & Objective
- Address the inefficiency of classical Fisher-Yates and hash-based membership checking algorithms when k ≪ n, which require O(n) space and suboptimal time.
- Develop a sparse representation using hash tables to store only modified array entries, reducing space and time complexity to O(k).
- Enable efficient sampling in sequential and distributed settings, including streaming data and merged datasets from multiple sources.
- Provide a unified framework linking various sampling methods through permutation generation and representation.
- Design algorithms suitable for scenarios where n is known but k is unknown, or where data is distributed across machines.
Proposed method
- Replace dense array initialization in Fisher-Yates with a hash table to store only indices that have been swapped, reducing space to O(k).
- Use the Sparse Fisher-Yates algorithm to generate a random sample in O(k) time and space by simulating swaps only on affected indices.
- Adapt the Beta-Binomial method to sample item positions in order using Dirichlet and multinomial distributions over uniform spacings.
- Utilize the Beta-Binomial distribution to model the position of the i-th sampled item as X_i ~ Beta-Binomial(1, k, n-k) + 1, enabling in-order sampling.
- Enable distributed sampling by modeling the number of items from each node in a merged sample using Beta and Binomial distributions.
- Implement a merging algorithm for distributed samples using auxiliary uniform variables and order statistics to compute the number of items to sample from each dataset.
Experimental results
Research questions
- RQ1Can we design a sampling algorithm that achieves optimal O(k) time and space complexity when k ≪ n, avoiding the O(n) initialization cost of classical Fisher-Yates?
- RQ2How can we efficiently support sequential sampling when k is unknown in advance, such as in adaptive sampling for variance estimation?
- RQ3What is the most efficient way to perform distributed random sampling across multiple machines with minimal communication and optimal sample size?
- RQ4How can we merge independent random samples from multiple datasets into a single simple random sample without recomputing from scratch?
- RQ5Can we unify various sampling methods through a common framework based on permutation generation and representation?
Key findings
- The Sparse Fisher-Yates algorithm achieves O(k) time and space complexity by using a hash table to represent only modified array entries, eliminating the need for O(n) initialization.
- The algorithm draws exactly k uniform random variates and produces the same output as classical Fisher-Yates, but with optimal space and time complexity.
- The Beta-Binomial in-order sampler enables efficient, ordered sampling by modeling item positions using Beta-Binomial distributions, with the i-th item’s position distributed as Beta-Binomial(i, k−i+1, n−k)+i.
- The merging algorithm for distributed samples uses auxiliary uniform variables and order statistics to compute the number of items to sample from each dataset, ensuring a valid simple random sample of the union.
- The method allows for efficient downsampling of merged samples by computing κ₁ and κ₂ via Binomial distributions conditioned on relative thresholds T₁ and T₂.
- The proposed algorithms are simpler to implement and more efficient than existing methods like hash-based membership checking, which suffer from expected O(n log(n/(n−k))) time complexity when k is close to n.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.