Introduction
Generating random permutations, or shuffling, is a cornerstone of randomized algorithms and simulations. For decades, the Fisher-Yates shuffle has served as the standard due to its simplicity and minimal randomness requirements. However, Fisher-Yates is inherently sequential; each swap depends on previous iterations, creating a bottleneck on modern multi-core architectures.
This paper introduces MergeShuffle, a "divide-and-conquer" algorithm that mirrors the structure of MergeSort. MergeShuffle is designed for high-performance, in-place execution and easy parallelization, significantly outperforming Fisher-Yates at scale while maintaining high efficiency in the "random-bit model."
Methodology
MergeShuffle adapts the recursive logic of MergeSort to the shuffling problem through three primary stages:
- Divide: The input array is recursively partitioned into smaller blocks.
- Base Case: Once blocks reach a predefined size threshold, they are shuffled using the traditional Fisher-Yates method.
- Merge: The core innovation is an In-Place Shuffled Merging procedure. Unlike standard merging which compares values, this procedure uses random bits (coin flips) to determine which sub-array to draw from next. This ensures the resulting merged array is a perfect random permutation of its constituents.
The authors also explore BalancedShuffle, a theoretical variant that uses "balanced words" (binary strings with equal counts of 0s and 1s) to ensure perfectly equal recursive partitions. While BalancedShuffle is highly bit-efficient, it currently requires auxiliary memory, making it less practical than the in-place MergeShuffle.
Experimental Setup
The algorithms were evaluated using synthetic arrays ranging from $10^5$ to $10^9$ elements. Benchmarking was conducted on a 40-core computing cluster utilizing the OpenMP library for parallel execution. The study focused on two primary metrics: execution time and the total number of random bits consumed.
Results and Discussion
Performance and Scalability
The experimental results highlight a significant performance shift as array sizes grow. While Fisher-Yates is efficient for small datasets, its performance degrades relative to parallel alternatives once the array size exceeds $10^7$ elements.
As shown in the figure above, the parallel implementation of MergeShuffle (MergeShuffle PAR) scales effectively with the number of processor cores. In contrast, the sequential nature of Fisher-Yates leads to a steep increase in execution time for massive arrays ($10^9$ elements). MergeShuffle also benefits from better cache locality, as it operates on localized data blocks before merging.
Bit Consumption and Efficiency
In the random-bit model, efficiency is measured by the number of individual random bits consumed. MergeShuffle uses approximately $n \log_2 n + \Theta(n)$ bits, nearing the information-theoretic lower bound.
The table above confirms that MergeShuffle's bit consumption is comparable to the Rao-Sandelius algorithm, one of the most bit-efficient methods known. While BalancedShuffle shows slightly higher bit counts in these tests, its theoretical properties remain a subject of interest for future optimization.
Conclusion and Future Work
MergeShuffle represents a significant advancement in parallel shuffling, offering an in-place, scalable alternative to traditional sequential methods. While it already outperforms Fisher-Yates at scale, the authors identify several areas for improvement. Currently, the performance lead over the Rao-Sandelius algorithm is modest, and the BalancedShuffle variant requires a more efficient C implementation to be truly competitive. Future research will focus on more aggressive parallelization strategies to further reduce time complexity on exascale datasets.
Summary updated