Abstract
We present a new Gray code for combinations that is practical and elegant. We represent combinations as bitstrings with s 0’s and t 1’s, and generate them with a remarkably simple rule: Identify the shortest prefix ending in 010 or 011 (or the entire bitstring if no such prefix exists) and then rotate (shift) it by one position to the right. Since the rotated portion of the string consists of at most four contiguous runs of 0’s and 1’s, each successive combination can be generated by transposing only one or two pairs of bits. This leads to a very efficient loopless implementation. The Gray code also has a simple and efficient ranking algorithm that closely resembles that of combinations in colex order. For this reason, we have given a nickname to our order: cool-lex!
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Corbett, P.F.: Rotator Graphs: An Efficient Topology for Point-to-Point Multiprocessor Networks. IEEE Transactions on Parallel and Distributed Systems 3, 622–626 (1992)
Chase, P.J.: Combination Generation and Graylex Ordering. Congressus Numerantium 69, 215–242 (1989)
Diaconis, P., Holmes, S.: Gray codes for randomization procedures. Statistical Computing 4, 207–302 (1994)
Eades, P., Hickey, M., Read, R.: Some Hamilton Paths and a Minimal Change Algorithm. Journal of the ACM 31, 19–29 (1984)
Eades, P., McKay, B.: An Algorithm for Generating Subsets of Fixed Size with a Strong Minimal Change Property. Information Processing Letters 19, 131–133 (1984)
Ehrlich, G.: Loopless Algorithms for Generating Permutations, Combinations and Other Combinatorial Configurations. Journal of the ACM 20, 500–513 (1973)
Jiang, M., Ruskey, F.: Determining the Hamilton-connectedness of certain vertex-transitive graphs. Discrete Mathematics 133, 159–170 (1994)
Knuth, D.E.: The Art of Computer Programming, pre-fascicle 4A (a draft of Section 7.2.1.3: Generating all Combinations), p. 61. Addison-Wesley, Reading (2004), http://www-cs-faculty.stanford.edu/~knuth/fasc3a.ps.gz
Ruskey, F.: Simple combinatorial Gray codes constructed by reversing sublists. In: Ng, K.W., Balasubramanian, N.V., Raghavan, P., Chin, F.Y.L. (eds.) ISAAC 1993. LNCS, vol. 762, pp. 201–208. Springer, Heidelberg (1993)
Tang, D.T.: C.N. Liu Distance-2 Cycle Chaining of Constant Weight Codes. IEEE Transactions C-22, 176–180 (1973)
Stanton, D., White, D.: Constructive Combinatorics. Springer, Heidelberg (1986)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2005 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Ruskey, F., Williams, A. (2005). Generating Combinations by Prefix Shifts. In: Wang, L. (eds) Computing and Combinatorics. COCOON 2005. Lecture Notes in Computer Science, vol 3595. Springer, Berlin, Heidelberg. https://doi.org/10.1007/11533719_58
Download citation
DOI: https://doi.org/10.1007/11533719_58
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-28061-3
Online ISBN: 978-3-540-31806-4
eBook Packages: Computer ScienceComputer Science (R0)