Generating combinations by prefix shifts

  • Authors:
  • Frank Ruskey;Aaron Williams

  • Affiliations:
  • Dept. of Computer Science, University of Victoria;Dept. of Computer Science, University of Victoria

  • Venue:
  • COCOON'05 Proceedings of the 11th annual international conference on Computing and Combinatorics
  • Year:
  • 2005

Quantified Score

Hi-index 0.00

Visualization

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!