We first present a simple recursive algorithm that generates cyclic rotation Gray codes for stamp foldings and semi-meanders, where consecutive strings differ by a stamp rotation. These are the first known Gray codes for stamp foldings and semi-meanders, and we thus solve an open problem posted by Sawada and Li in [Electron. J. Comb. 19(2), 2012]. We then introduce an iterative algorithm that generates the same rotation Gray codes for stamp foldings and semi-meanders. Both the recursive and iterative algorithms generate stamp foldings and semi-meanders in constant amortized time and $O(n)$-amortized time per string respectively, using a linear amount of memory.
翻译:我们首先提出一种简单的递归算法,用于生成邮票折叠与半蜿蜒结构的循环旋转格雷码,其中相邻字符串仅相差一次邮票旋转操作。这是首次针对邮票折叠与半蜿蜒结构提出的格雷码构造方法,从而解决了Sawada与Li在[Electron. J. Comb. 19(2), 2012]中提出的公开问题。随后我们提出一种迭代算法,可生成相同的邮票折叠与半蜿蜒结构旋转格雷码。递归算法与迭代算法分别以常数分摊时间与$O(n)$分摊时间生成每个字符串,且仅需线性内存空间。