Generating Combinations by Prefix Shifts

نویسندگان

  • Frank Ruskey
  • Aaron Williams
چکیده

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! 1 Background and motivation An important class of computational tasks is the listing of fundamental combinatorial structures such as permutations, combinations, trees, and so on. Regarding combinations, Donald E. Knuth [8] writes “Even the apparently lowly topic of combination generation turns out to be surprisingly rich, .... I strongly believe in building up a firm foundation, so I have discussed this topic much more thoroughly than I will be able to do with material that is newer or less basic.” The applications of combination generation are numerous and varied, and Gray codes for them are particularly valuable. We mention as application areas cryptography (where they have been implemented in hardware at NSA), genetic algorithms, software and hardware Dept. of Computer Science, University of Victoria, research supported in part by NSERC. e-mail: [email protected] Dept. of Computer Science, University of Victoria, research supported in part by a NSERC PGS-D. e-mail: [email protected]

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Generating Balanced Parentheses and Binary Trees by Prefix Shifts

We show that the set Bn of balanced parenthesis strings with n left and n right parentheses can be generated by prefix shifts. If b1, b2, . . . , b2n is a member of Bn, then the k-th prefix shift is the string b1, bk, b2, . . . , bk−1, bk+1, . . . , b2n. Prefix shift algorithms are also known for combinations, and permutations of a multiset; the combination algorithm appears in fascicles of Knu...

متن کامل

The coolest way to generate combinations

We present a practical and elegant method for generating all (s, t)-combinations (binary strings with s zeros and t ones): Identify the shortest prefix ending in 010 or 011 (or the entire string if no such prefix exists), and rotate it by one position to the right. This iterative rule gives an order to (s, t)-combinations that is circular and genlex. Moreover, the rotated portion of the string ...

متن کامل

Ranking and Loopless Generation of k-ary Dyck Words in Cool-lex Order

A binary string B of length n = kt is a k-ary Dyck word if it contains t copies of 1, and the number of 0s in every prefix of B is at most k−1 times the number of 1s. We provide two loopless algorithms for generating k-ary Dyck words in cool-lex order: (1) The first requires two index variables and assumes k is a constant; (2) The second requires t index variables and works for any k. We also e...

متن کامل

COUNTEREXAMPLES IN CHAOTIC GENERALIZED SHIFTS

‎In the following text for arbitrary $X$ with at least two elements‎, ‎nonempty countable set $Gamma$‎ ‎we make a comparative study on the collection of generalized shift dynamical systems like $(X^Gamma,sigma_varphi)$ where $varphi:GammatoGamma$ is an arbitrary self-map‎. ‎We pay attention to sub-systems and combinations of generalized shifts with counterexamples regarding Devaney‎, ‎exact Dev...

متن کامل

Shift Gray Codes

Combinatorial objects can be represented by strings, such as 21534 for the permutation (1 2) (3 5 4), or 110100 for the binary tree corresponding to the balanced parentheses (()()). Given a string s = s1s2⋯sn, the right-shift operation ÐÐ→ shift(s, i, j) replaces the substring sisi+1⋯sj by si+1⋯sjsi. In other words, si is right-shifted into position j by applying the permutation (j j−1 ⋯ i) to ...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2005