We give the first two algorithms to enumerate all binary words of $\{0,1\}^\ell$ (like Gray codes) while ensuring that the delay and the auxiliary space is independent from $\ell$, i.e., constant time for each word, and constant memory in addition to the $\ell$ bits storing the current word. Our algorithms are given in two new computational models: tape machines and deque machines. We also study more restricted models, queue machines and stack machines, and show that they cannot enumerate all binary words with constant auxiliary space, even with unrestricted delay. A tape machine is a Turing machine that stores the current binary word on a single working tape of length $\ell$ (which never increases), using no other tape. The machine has a single head and must edit its tape to reach all possible words of $\{0,1\}^\ell$, and output them (in unit time, by entering special output states), with no duplicates. Hence a tape machine uses constant auxiliary space by definition (up to the head position). We construct a tape machine that achieves this task with constant delay between consecutive outputs, so that the machine implements a so-called skew-tolerant quasi-Gray code. We then construct a more involved tape machine that implements a Gray code. A deque machine stores the current binary word on a double-ended queue of length $\ell$, and stores a constant-size internal state. It works as a tape machine, except that it modifies the content of the deque by performing push and pop operations on the endpoints. Hence again a deque machine uses constant auxiliary space by definition. We construct deque machines that enumerate all words of $\{0,1\}^\ell$ with constant-delay. The main technical challenge in this model is to correctly detect when enumeration has finished.
翻译:本文给出了首批两种算法,用于枚举 $\{0,1\}^\ell$ 中的所有二进制字(类似于格雷码),同时确保延迟和辅助空间与 $\ell$ 无关,即每个字的枚举时间为常数,且除存储当前字的 $\ell$ 位外,内存占用为常数。我们的算法基于两种新型计算模型:带机模型与双端队列机模型。此外,我们研究了更受限的模型——队列机模型与栈机模型,并证明即使允许无限制延迟,也无法在常数辅助空间内枚举所有二进制字。带机是一种图灵机,其将当前二进制字存储于长度为 $\ell$(且永不增长)的单条工作带上,不使用其他磁带。该机器仅有一个读写头,需通过编辑磁带以遍历 $\{0,1\}^\ell$ 中所有可能的字,并按(单位时间)输出(通过进入特殊输出状态),且不产生重复。因此,带机天然使用常数辅助空间(除磁头位置外)。我们构造了一个带机,其能实现相邻输出间常数延迟,从而执行所谓的容忍偏斜准格雷码。随后,我们构造了一个更复杂的带机,实现完整的格雷码。双端队列机将当前二进制字存储于长度为 $\ell$ 的双端队列中,并维护一个常数大小的内部状态。其工作方式与带机类似,但通过端点上的推入和弹出操作修改队列内容。因此,双端队列机同样天然使用常数辅助空间。我们构造了双端队列机,以常数延迟枚举 $\{0,1\}^\ell$ 中的所有字。该模型的主要技术挑战在于正确检测枚举何时结束。