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$. 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. We construct a tape machine that achieves this task with constant delay between consecutive outputs, which implies 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. 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. Our work on deque machine is also motivated by other contexts in which endpoint modifications occur naturally. In particular, our result is a first step towards enumerating walks in directed graphs with constant delay and constant auxiliary space, addressing a core task in modern graph database query processing.
翻译:我们首次提出了两种算法,能够枚举所有$\{0,1\}^\ell$中的二进制字(类似于格雷码),同时确保延迟和辅助空间与$\ell$无关,即每个字的处理时间为常数,且除存储当前字的$\ell$位内存外,仅需常数内存。我们的算法基于两种新的计算模型:磁带机与双端队列机。我们还研究了更受限的模型——队列机与栈机,并证明即使允许无限制延迟,它们也无法在常数辅助空间下枚举所有二进制字。磁带机是一种将当前二进制字存储在长度为$\ell$的单条工作磁带上的图灵机。该机器具有单个磁头,必须通过编辑磁带来遍历$\{0,1\}^{\ell}$中的所有可能字,并输出它们(通过进入特殊输出状态以单位时间完成),且不允许重复。我们构建了一种磁带机,能够在连续输出间实现恒定延迟,这意味着该机器实现了所谓的容偏斜准格雷码。随后,我们构建了一种更复杂的磁带机来实现标准格雷码。双端队列机将当前二进制字存储在长度为$\ell$的双端队列上,并维护一个常数大小的内部状态。其操作方式类似于磁带机,但通过对队列端点执行压入和弹出操作来修改队列内容。我们构建了能够以恒定延迟枚举所有$\{0,1\}^\ell$中字的双端队列机。该模型中的主要技术挑战在于正确检测枚举何时完成。我们对双端队列机的研究也受到其他自然涉及端点修改的应用场景的推动。特别地,我们的成果是朝着以恒定延迟和恒定辅助空间枚举有向图中路径迈出的第一步,这直接关联现代图数据库查询处理中的核心任务。