Abstract 1 Introduction 2 Preliminaries 3 Exploration on Arbitrary Graphs 4 Exploration on 𝝋-free Graphs 5 Conclusion References Appendix A The Omitted Proof for Triangle-free Case Appendix B Model Clarification

Recolorable Graph Exploration by an Oblivious Agent with Fewer Colors

Shota Takahashi ORCID Hosei University, Tokyo, Japan Haruki Kanaya ORCID Nara Institute of Science and Technology, Ikoma, Japan Shoma Hiraoka ORCID The University of Osaka, Suita, Japan Ryota Eguchi ORCID Nara Institute of Science and Technology, Ikoma, Japan Yuichi Sudo ORCID Hosei University, Tokyo, Japan
Abstract

Recently, Böckenhauer, Frei, Unger, and Wehner (SIROCCO 2023) introduced a novel variant of the graph exploration problem in which a single memoryless agent must visit all nodes of an unknown, undirected, and connected graph before returning to its starting node. Unlike the standard model for mobile agents, edges are not labeled with port numbers. Instead, the agent can color its current node and observe the color of each neighboring node. To move, it specifies a target color and then moves to an adversarially chosen neighbor of that color. They analyzed the minimum number of colors required for successful exploration and proposed an elegant algorithm that enables the agent to explore an arbitrary graph using only eight colors. In this paper, we present a novel graph exploration algorithm that requires only six colors. Furthermore, we prove that five colors are sufficient if we consider only a restricted class of graphs, which we call the φ-free graphs, a class that includes every graph with maximum degree at most three and every cactus.

Keywords and phrases:
mobile agents, recolorable graphs, graph exploration
Funding:
Yuichi Sudo: This work is supported by JST FOREST Program JPMJFR226U and JSPS KAKENHI Grant Numbers JP20KK0232, JP25K03078, and JP25K03079.
Copyright and License:
[Uncaptioned image] © Shota Takahashi, Haruki Kanaya, Shoma Hiraoka, Ryota Eguchi, and Yuichi Sudo; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Distributed algorithms
Related Version:
Previous Version: https://arxiv.org/abs/2505.02789
Editors:
Andrei Arusoaie, Emanuel Onica, Michael Spear, and Sara Tucci-Piergiovanni

1 Introduction

Autonomous mobile entities that migrate from node to node on a graph – commonly referred to as mobile agents or simply agents – have been extensively studied in the theoretical distributed computing community. Numerous fundamental problems involving these agents have been investigated in the literature, including graph exploration [13, 12, 14, 18, 19, 3], gathering [11, 16] (called rendezvous if exactly two agents are considered), dispersion [8, 9, 10, 1, 20], uniform deployment [15, 17], black hole search [5, 6, 7], and others.

Among these, graph exploration (performed by a single agent) is arguably one of the most fundamental problems, since exploration algorithms often serve as building blocks for solving many other problems. The objective is to enable the agent to visit every node in a graph, return to its starting node, and then terminate. This problem has been studied under various settings: the nodes may be labeled or anonymous; the agent may have access to the local memories of the nodes (often referred to as whiteboards); the agent may have its own memory or be oblivious; and the initial configuration may be fixed or arbitrary (in which case the solution is self-stabilizing), among others.

All these settings for graph exploration share a common characteristic: the edges are locally labeled with port numbers. Typically, in a graph G=(V,E), the edges incident to a node vV are assigned distinct port numbers 0,1,,δv1, where δv is the degree of v. The agent uses these port numbers to distinguish between the edges and decide which neighbor to move to. Moreover, most studies in the literature assume that the agent can access the incoming port information: when the agent moves from a node u to v, it learns the port number assigned to the edge {u,v} at the destination v, whereas the well-known rotor-router algorithm [13] and some other algorithms [3] do not use this information.

In 2023, Böckenhauer, Frei, Unger, and Wehner [2] introduced a surprisingly novel model for mobile agents in which port numbers are unavailable. Moreover, they assume that the nodes are anonymous and that the agent is oblivious, so additional assumptions are required to make graph exploration feasible. To overcome these limitations, they introduced node coloring. Specifically, at each time step, the agent at a node v can observe the color of v as well as the colors of its neighboring nodes. Based on this information, the agent updates the color of v and computes a destination color c, after which it moves to a neighbor with color c. If two or more neighbors of v are colored c, the destination is selected adversarially among them. At the start of exploration, all nodes are assigned a common initial color.

The authors of [2] thoroughly investigated the minimum number of colors required to solve this new variant of the graph exploration problem. It is worth mentioning that they measure color complexity by excluding the initial color. In contrast, we include the initial color in our count – a convention we believe improves clarity. Consequently, whenever we refer to results from [2], our reported color counts are always one greater.

If the agent is restricted to changing the color of each node at most once, they prove that n colors are both necessary and sufficient for arbitrary simple, undirected, and connected graphs, while four colors are necessary and sufficient for trees. (Throughout the remainder of this paper, we assume that the graph is simple, undirected, and connected, and thus omit this assumption from subsequent descriptions.) They further show that n1 colors remain necessary even for bipartite graphs of size n=|V|. Moreover, they prove that if the exact network size n=|V| is known, then n2 and n1 colors are necessary and sufficient, respectively, for exploring arbitrary graphs.

In the model where the agent is allowed to recolor each node an unlimited number of times, which we refer to as the recolorable model, the color complexity decreases significantly. Specifically, they prove that eight colors are sufficient to explore arbitrary graphs, although no lower bound is provided.

To be candid, we could find no immediate practical application for this exploration setting. However, we believe that this new variant holds significant theoretical interest. In the absence of port numbers, most of the commonly used techniques for graph exploration and related problems cannot be applied. Consequently, entirely novel methods are required to minimize the color complexity. In this regard, the new model introduced by [2] may pave the way for exciting new avenues of research in the field of mobile agents.

Our Contribution

In this paper, we address the aforementioned variant of graph exploration introduced by [2]. In particular, within the recolorable model, we present an exploration algorithm for arbitrary graphs that uses only six colors, improving on the eight-color bound of [2] by two. Moreover, for triangle-free graphs – those containing no cycle of length 3 – this algorithm can be adapted to use only five colors. We also prove that five colors suffice for another restricted class of graphs, which we call φ-free graphs (see Section 4); this class includes all graphs of maximum degree 3 and all cactus graphs.

Similarly to [2], we do not provide any non-trivial lower bound for exploration on arbitrary graphs in the recolorable model. Therefore, the main open question is whether six colors are indeed necessary or if this number can be further reduced. Another promising direction for future research is to allow the agent to have its own internal memory. Even a constant number of bits – or even just one bit – might significantly help to reduce the required number of colors.

 Note 1.

This paper adheres strictly to the original model of Böckenhauer, Frei, Unger, and Wehner [2], but there is one ambiguity – apparently due to a typo in their definition – concerning whether the agent may recolor a node from a non-initial color back to the initial color. In this paper, we assume that it can, and we conjecture that the authors of [2] intended the same (see Section B in the appendix for details). If this ability were disallowed, the color complexity of our first two algorithms – for arbitrary graphs and for triangle-free graphs – would each increase by one (to seven and six, respectively). In contrast, our third algorithm for φ-free graphs would remain unchanged, since it never relies on recoloring back to the initial color. We further conjecture that even a substantial modification of the eight-color algorithm of [2] would not benefit from this capability.

2 Preliminaries

Throughout this paper, the term graph refers exclusively to a simple, undirected, and connected graph.

An algorithm is defined as a triple 𝒜=(C,c0,ξ), where C is a set of colors, c0C is the initial color, and

ξ:C×(C)C×(C{𝗌𝗍𝖺𝗒,𝗌𝗍𝗈𝗉})

is a rule function. Here, (C) denotes the set of all multisets over C, that is, all functions m:C0, where 0 is the set of nonnegative integers. When an agent executes 𝒜 on a graph G=(V,E), the execution proceeds as follows. Let vt be the node where the agent is located at time t=0,1,2,, and let c(v,t) denote the color of the node vV at time t. Initially, every node is assigned the color c0, i.e., c(v,0)=c0 for all vV. At each time step t, the agent observes the color of its current node vt and the colors of all its neighbors. More precisely, it obtains the current color c(vt,t) and the multiset M=uN(vt){c(u,t)}. Here, the symbol denotes the sum (union) of multisets, and N(v) represents the set of neighbors of a node vV. The agent then recolors vt with a new color x and moves to a neighbor with color y, where

(x,y)=ξ(c(vt,t),M).

Note that if more than one neighbor in N(vt) has color y, the agent moves to one of those nodes, with the choice made adversarially. We have two exceptions:

  • The agent stays at the current node vt if y=𝗌𝗍𝖺𝗒111In [2], the stay option 𝗌𝗍𝖺𝗒 is not included. Note that introducing the stay option does not change or extend the model: if ξ(c,M)=(x,𝗌𝗍𝖺𝗒), then we can equivalently define the rule function recursively by setting ξ(c,M)=ξ(x,M), as in the original model. , and

  • The agent terminates its execution at vt if y=𝗌𝗍𝗈𝗉 or yM holds.

Even in these exceptional cases, the agent recolors vt with x.

A global state, or configuration, is a triple γ=(v,ψ,b), where vV is the current node where the agent is located, ψ:VC assigns a color to every node, and b{𝐟𝐚𝐥𝐬𝐞,𝐭𝐫𝐮𝐞} indicates whether the algorithm has terminated. We write γγ to denote that configuration γ transitions to γ by one action of the agent (i.e., by updating the color and executing a movement or termination). We denote by γinit(v) the configuration in which all nodes are colored c0, the agent is located at node v, and the agent has not terminated. A finite or infinite sequence =γ0,γ1, of configurations is called an execution of an algorithm 𝒜 starting at node v if γ0=γinit(v) and γtγt+1 holds for every consecutive pair of configurations. We say that an execution is maximal if it is infinite or if the agent has terminated in its last configuration.

Definition 2 (Graph Exploration).

An algorithm 𝒜 is said to solve exploration on a graph G=(V,E) if, for any node sV, the agent visits every node in V and terminates at s in every maximal execution of 𝒜 starting at s.

Our goal is to minimize the number of colors used in graph exploration. For an algorithm 𝒜=(C,c0,ξ), we define the number of colors to be |C|. Note that in the original work by Böckenhauer, Frei, Unger, and Wehner [2], the number of colors is defined as |C|1, since the initial color c0 is not counted. In this paper, we count the initial color c0, as this definition may be clearer for most readers.

3 Exploration on Arbitrary Graphs

In this section, we show that six colors suffice for exploring arbitrary graphs. Böckenhauer, Frei, Unger, and Wehner [2] presented a simple and elegant algorithm for graph exploration that employs eight colors. In their algorithm, the agent visits all nodes in a breadth-first search (BFS) manner and terminates at the starting node s. To reduce the number of colors, we adopt a different approach in which the agent explores the graph in a manner reminiscent of depth-first search (DFS), though its movement deviates slightly. We refer to this approach as the semi-DFS. In the remainder of this section, we first explain the semi-DFS and then show how the agent can simulate it using only six colors.

Figure 1: An example configuration illustrating why simulating DFS is difficult. The agent must backtrack from u5 to u4, but it cannot determine which neighbor of u5 corresponds to u4.

3.1 Semi-DFS

A depth-first search (DFS) can be described in terms of a maintained path P and a set F of finished nodes, as follows:

  1. 1.

    Initially, set P=(s) and F=, where s is the starting node.

  2. 2.

    Let P=(u1,u2,,uk). If there exists a neighbor uN(uk)(F{u1,u2,,uk}), choose any such node and append it to P. Otherwise, remove the last node (or head) uk from P and add it to F.

  3. 3.

    If P is empty (i.e., P=()), terminate; otherwise, return to step (2).

Generally speaking, during a DFS, two nodes ui and uj in the path P=(u1,u2,,uk) may be adjacent even if |ij|1. In particular, the head uk may have two or more neighbors that belong to P. When the agent attempts to simulate DFS using a constant number of colors, this fact poses a significant challenge (Figure 1). To backtrack from uk to uk1, the agent must distinguish uk1 from the other neighbors of uk. If we were allowed to assign different colors to the k1 nodes u1,u2,,uk1, the agent could easily identify uk1. However, this approach would require Ω(|V|) colors generally. Thus, there appears to be no straightforward way to implement DFS with a constant number of colors.

Algorithm 1 Semi-DFS.
Algorithm 2 Graph Exploration Algorithm for General Graphs 𝒜Gen6=(CGen6,𝗂𝗇𝗂𝗍,ξGen6).

Therefore, we modify DFS so that any two nodes ui,uj in the path P=(u1,u2,,uk) are adjacent only when |ij|=1. We refer to this modified algorithm as the semi-DFS. As we shall see in Section 3.2, this property greatly facilitates graph exploration. The pseudocode for the semi-DFS is provided in Algorithm 1. The sole difference from the original DFS occurs during path expansion: we extend the path P=(u1,u2,,uk) only if the property is preserved. Specifically, let U denote the set of neighbors of uk that have not been visited and are not adjacent to any node in the earlier part of the path, i.e., U(P,F)=N(uk)(F{u1,u2,,uk}i=1k1N(ui)). If U, we expand the path; otherwise, we backtrack from uk to uk1.

Lemma 3.

For any graph G=(V,E) and for any starting node sV, the semi-DFS algorithm eventually terminates, and by the time it terminates, every node in G has been visited (i.e., F=V eventually holds).

Proof of Lemma 3.

We prove that Algorithm 1 terminates and that F=V holds upon termination.

Termination.

At each iteration of the while loop, either (i) a node is appended to the path P, or (ii) a node is removed from P and added to F. Since each node can be appended to P at most once and removed from P at most once – and once a node is added to F, it is never removed – the total number of iterations is bounded by 2|V|. Hence, the algorithm terminates after a finite number of iterations.

Full Visitation.

Let XV be the set F upon termination. Assume, for the sake of contradiction, that XV. Since G is connected, the boundary set B(X)={vXuVX:{u,v}E} is not empty. Let vin be the node in B(X) that was removed from the return path P most recently, and choose any voutN(vin)X. Suppose the return path was P=(u1,u2,,uk) with vin=uk at the moment when vin was removed, at which U(P,F)=N(uk)(F{u1,u2,,uk}i=1k1N(ui)) must be empty. Since voutN(uk), at least one of the following must hold:

  1. 1.

    voutFX,

  2. 2.

    vout{u1,u2,,uk}X, or

  3. 3.

    vout is adjacent to some ui with 1ik1.

Cases 1 and 2 contradict voutX. Case 3 yields uiB(X) for some i<k, contradicting the choice of vin as the most recently removed boundary node. Hence X=V, as required.

Figure 2: Lifecycle of node colors in algorithm 𝒜Gen6.

3.2 How to simulate Semi-DFS with Six Colors

In this section, we present an algorithm 𝒜Gen6=(CGen6,𝗂𝗇𝗂𝗍,ξGen6) that enables the agent to explore a graph using six colors, namely 𝗂𝗇𝗂𝗍, 𝗉𝖺𝗍𝗁, 𝖿𝗂𝗇, 𝗁𝖾𝖺𝖽𝟣, 𝗁𝖾𝖺𝖽𝟤, and 𝗇𝖾𝗂𝗀𝗁, by simulating the movement of semi-DFS. The definition of 𝒜Gen6 is given in Algorithm 2. Some readers might be concerned about the absence of a definition for ξGen6(𝖿𝗂𝗇,M) in Algorithm 2; however, this poses no issue since, as we shall see later, the agent is located at a node colored 𝖿𝗂𝗇 only after the algorithm terminates. Figure 2, which describes how a node changes its color from 𝗂𝗇𝗂𝗍 to 𝖿𝗂𝗇, may help the reader quickly grasp the algorithm.

Algorithm 𝒜Gen6 simulates the Semi-DFS specified by Algorithm 1. In 𝒜Gen6, nodes colored 𝖿𝗂𝗇 represent finished nodes (i.e., the nodes in F), while nodes colored 𝗉𝖺𝗍𝗁 and 𝗁𝖾𝖺𝖽𝟣 form the path P of the semi-DFS. Nodes colored 𝗂𝗇𝗂𝗍 indicate that they are neither finished nor on P. The colors 𝗁𝖾𝖺𝖽𝟤 and 𝗇𝖾𝗂𝗀𝗁 are employed to find a node in U(P,F)=N(uk)(F{u1,u2,,uk}i=1k1N(ui)). A detailed explanation of 𝒜Gen6 is provided in the proof of the following theorem.

Theorem 4.

Algorithm 𝒜Gen6=(CGen6,𝗂𝗇𝗂𝗍,ξGen6), which uses six colors, solves the exploration problem on any graph G=(V,E).

Proof.

We fix a starting node sV and consider an arbitrary execution =γ0,γ1, of 𝒜Gen6 starting at s. To prove correctness, it suffices to show that is finite and that every node is colored 𝖿𝗂𝗇 in the final configuration since a node is recolored from the initial color 𝗂𝗇𝗂𝗍 only after it has been visited.

We say that a configuration γ=(v,ψ,b) of 𝒜Gen6 is regular if either

  1. 1.

    b=𝐭𝐫𝐮𝐞, v=s, and every node u is colored 𝖿𝗂𝗇 (i.e., ψ(u)=𝖿𝗂𝗇), or

  2. 2.

    b=𝐟𝐚𝐥𝐬𝐞 and there exists a path P=(u1,u2,,uk) with k1 such that u1=s, uk=v, ui and uj are adjacent only when |ij|=1 for all 1i,jk, ψ(uk)=𝗁𝖾𝖺𝖽𝟣, ψ(ui)=𝗉𝖺𝗍𝗁 for all 1i<k, and every node not on P is colored either 𝗂𝗇𝗂𝗍 or 𝖿𝗂𝗇.

Note that in any regular configuration, no node is colored 𝗇𝖾𝗂𝗀𝗁 or 𝗁𝖾𝖺𝖽𝟤. We refer to the regular configuration satisfying the first condition as the final configuration. If a configuration γ is regular but not final, we denote the unique path defined above by P(γ) and call it the return path of γ. Moreover, we denote F(γ)={uV:ψ(u)=𝖿𝗂𝗇}.

In the initial configuration γ0, each node has color 𝗂𝗇𝗂𝗍, and the agent is located at s. Therefore, by Rule 3, only s is colored 𝗁𝖾𝖺𝖽𝟣, while all other nodes remain colored 𝗂𝗇𝗂𝗍, and the agent remains at s in γ1. This configuration γ1 is regular and corresponds to the initial setting in the semi-DFS, i.e., P(γ0)=(s) and F(γ0)=. In the remainder of this proof, we show that from any regular but non-final configuration γ, 𝒜Gen6 simulates one iteration of the semi-DFS while loop, yielding a new regular configuration. By Lemma 3, it follows that eventually reaches a final configuration, thereby proving correctness.

Figure 3: Path expansion.
Figure 4: Removal of the head.

Let γ=(v,ψ,b) be any regular, non-final configuration. In γ, the agent is located at the head of the return path P(γ)=(u1,u2,,uk); that is, the agent is at node v=uk, which is colored 𝗁𝖾𝖺𝖽𝟣. Our goal is to verify that the agent simulates one iteration of the while loop of the semi-DFS from this configuration: if there exists a node in U(P(γ),F(γ))=N(uk)(F(γ){u1,u2,,uk}i=1k1N(ui)), the agent appends an arbitrary such node to P; if U(P(γ),F(γ))= and k2, the agent removes the head uk from P and backtracks to uk1, recoloring uk with 𝖿𝗂𝗇; otherwise, the agent terminates.

Let I(γ)={uN(uk)ψ(u)=𝗂𝗇𝗂𝗍}. By Rule 4, the agent visits each node uI(γ) one by one. Checking whether uU(P(γ),F(γ)) is straightforward: since u is colored 𝗂𝗇𝗂𝗍, it belongs to U(P(γ),F(γ)) if and only if none of its neighbors is colored 𝗉𝖺𝗍𝗁. The agent colors u with 𝗁𝖾𝖺𝖽𝟣 if uU(P(γ),F(γ)), and with 𝗇𝖾𝗂𝗀𝗁 otherwise, after which the agent returns to uk (Rules 1 and 2). We now consider two cases (Figures 4 and 4 may help the reader quickly grasp the two scenarios).

Case 1: 𝑼(𝑷,𝑭).

In this case, the agent visits the nodes in I(γ), recoloring them with 𝗇𝖾𝗂𝗀𝗁, until it encounters a node uU(P,F). Then, the agent colors u with 𝗁𝖾𝖺𝖽𝟣 and returns to uk. At uk, upon observing that u is colored 𝗁𝖾𝖺𝖽𝟣, the agent recolors uk with 𝗁𝖾𝖺𝖽𝟤 (Rule 5). By Rules 6 and 11, the agent then visits all neighbors colored 𝗇𝖾𝗂𝗀𝗁 and reverts their colors back to 𝗂𝗇𝗂𝗍. Finally, the agent expands P by recoloring uk with 𝗉𝖺𝗍𝗁 and moving to u (Rule 7).

Case 2: 𝑼(𝑷,𝑭)=.

In this case, the agent recolors all nodes in I(γ) with 𝗇𝖾𝗂𝗀𝗁, recolors uk with 𝗁𝖾𝖺𝖽𝟤 (Rule 5), and reverts their colors back to 𝗂𝗇𝗂𝗍 (Rules 6 and 11). If k2, the agent moves to and recolors uk1 with 𝗁𝖾𝖺𝖽𝟣 (Rules 8 and 10); otherwise, it terminates (Rule 9). In any case, uk is recolored with 𝖿𝗂𝗇.

In both cases, we have shown that the agent correctly simulates one complete iteration of the semi-DFS while loop, resulting in a new regular configuration.

3.3 Triangle-free Case

When we restrict our attention to triangle-free graphs, i.e., graphs that contain no cycle of length 3, we can reduce the number of colors by one. Specifically, by merging the two colors 𝗁𝖾𝖺𝖽𝟣 and 𝗁𝖾𝖺𝖽𝟤, our algorithm requires only five colors. This yields the following theorem. A detailed description of the algorithm and its correctness is provided in the appendix (Section A).

Theorem 5.

There exists an algorithm that uses five colors and solves the exploration problem on any graph G=(V,E) containing no cycle of length 3.

Algorithm 3 Graph Exploration Algorithm for φ-free Graphs 𝒜PF5=(CPF5,𝗂𝗇𝗂𝗍,ξPF5). (Note: All arithmetic on indices in {0,1,2} is performed modulo 3; the modulo notation is omitted.)
Figure 5: φ-shaped graphs.
Figure 6: φ-shaped graph in the proof of Lemma 7.

4 Exploration on 𝝋-free Graphs

In this section, we show that five colors suffice for exploring φ-free graphs, defined below.

Definition 6 (φ-free graph).

A graph G=(V,E) is said to be φ-shaped if there exist three distinct nodes s,t,uV such that:

  • there exist three node-disjoint paths p1, p2, and p3 between s and t that do not contain u

  • every node in V{u} lies on at least one of p1, p2, or p3, and

  • {t,u}E,

A graph is said to be φ-free if it does not contain any φ-shaped subgraph.

Typical examples of φ-shaped graphs are shown in Figure 6. The term φ-free is derived from the shape of the φ-shaped graphs. Every graph with maximum degree at most three is φ-free, since in any φ-shaped graph the node t has degree four. Moreover, every cactus is also φ-free because every φ-shaped graph violates the cactus condition that no two cycles share more than one node. The following useful lemma holds.

Lemma 7.

A simple, undirected graph G=(V,E) is φ-free if and only if, for every node vV with degree at least four, no connected component of Gv contains three or more neighbors of v.

Proof.
Sufficiency.

Every φ-shaped graph contains a node t with degree at least four such that three neighbors of t lie in the same connected component of Gt (see Figure 6).

Necessity.

Assume that there exists a node tV with degree at least four for which three of its neighbors, say u1, u2, and u3, lie in the same connected component of Gt. Then, in that connected component of Gt, there is a spanning tree containing u1, u2, and u3. Consequently, there exists a node s in this component such that there are three node-disjoint paths q1, q2, and q3 in Gt, where each qi is a path from s to ui.

Now, by adding the edge {t,ui} to each qi, we obtain three node-disjoint paths p1, p2, and p3 from s to t in G. Let u4 be another neighbor of t different from u1, u2, and u3. If none of p1, p2, or p3 contains u4, then G contains a φ-shaped subgraph, as required. Otherwise, assume without loss of generality that p1 contains u4 (see Figure 6). Let q4 be the subpath of p1 connecting s and u4. Then, the three node-disjoint paths p4=q4+{u4,t}, p2, and p3 from s to t (with the edge {t,ui} appended as before) and edge {t,u1} form a φ-shaped subgraph. Note that this discussion holds even in s=u2 or s=u3.

As mentioned at the beginning of Section 3, The authors of [2] use eight colors to explore arbitrary graphs. Their approach employs a breadth-first search (BFS) strategy, encoding the distance between the starting node s and each node v modulo 3 as the color of v. Specifically, they use the color set

{𝗂𝗇𝗂𝗍,𝖿𝗂𝗇,g0,g1,g2,r0,r1,r2},

where we have renamed these colors to be consistent with our notation. As you can see, exactly two colors are used to encode each distance (modulo 3) from the starting node, which they refer to as the green and red colors. This multiplicity (i.e., having both a green and a red color for each distance) plays a critical role in computing the correct distance (modulo 3) from the starting node in the BFS manner. Given these distances, the agent has a sense of direction: when the agent is located at a node v with distance i{0,1,2}, the neighbors in N(v) with distance i1mod3 are the nodes closer to s, while those with distance i+1mod3 are the nodes further away. This sense of direction greatly facilitates the agent’s task of visiting all nodes in the graph.

In this section, we show that the multiplicity of colors (i.e., the separate green and red colors) can be eliminated when we consider only φ-free graphs. Our algorithm 𝒜PF5=(CPF5,𝗂𝗇𝗂𝗍,ξPF5) uses a color set of size five:

CPF5={𝗂𝗇𝗂𝗍,𝖿𝗂𝗇,d0,d1,d2}.

The key idea is to abandon computing the exact distance between each node v and the starting node s. Instead, we construct a directed acyclic graph (DAG) on the graph G=(V,E) using the three colors d0,d1,d2, which we refer to collectively as distance colors. Specifically, given a configuration γ=(v,ψ,b), we define a digraph D(γ)=(V,A) as follows:

A={(u,v)V×V{u,v}E,i{0,1,2} such that ψ(u)=di and ψ(v)=di+1}.

Intuitively, a node u colored di has an outgoing arc to a neighbor vN(u) if and only if v is colored di+1. Here and throughout, all arithmetic on indices in {0,1,2} is performed modulo 3 (the modulo notation is omitted for brevity); for example, d2+1=d0 and d01=d2. When no ambiguity arises, we omit the argument γ and simply denote D(γ) by D.

The definition of 𝒜PF5=(CPF5,𝗂𝗇𝗂𝗍,ξPF5) is provided in Algorithm 3. At time step 0, the agent colors the starting node s with d0 (Rule 3). Thereafter, the agent moves to a node with the initial color 𝗂𝗇𝗂𝗍 only from a node with a distance color by Rule 4. Upon arriving at a node colored 𝗂𝗇𝗂𝗍, say vV, the agent observes the multiset M=uN(v){c(u)}, where c(u) denotes the color of a neighbor uN(v). The agent then colors v based on this multiset M and the following two principles:

  1. 1.

    The digraph D must remain acyclic (i.e., no cycles are ever created), and

  2. 2.

    Any node v that is colored di for some i{0,1,2} must be reachable from s in D.

Specifically, Rule 2 enforces these principles: whenever {d0,d1,d2}M, the agent assigns v the color df(M), where

f(M)=min{i{0,1,2}di1M and di+1M}.

The first principle is preserved because no neighbor of v is colored df(M)+1, and the second principle is maintained because there is at least one neighbor colored df(M)1. Note that f(M) is uniquely determined here since M contains at least one distance color (recall that the agent has moved to v by Rule 4) and {d0,d1,d2}M. If, on the other hand, {d0,d1,d2}M, then the agent colors v with 𝖿𝗂𝗇 and then moves to an arbitrary neighbor with color d0 (Rule 1).

As mentioned above, the starting node s is colored d0. Consequently, in the digraph D, any node v with color di is at distance i from s (modulo 3). This provides the agent with a sense of direction, as in the eight-color algorithm of [2]. Suppose that the agent is at a node v with distance color di and none of its neighbors is colored 𝗂𝗇𝗂𝗍. Then, if there exists a neighbor with color di+1, the agent moves forward to that neighbor (Rule 5); otherwise, it backtracks to a neighbor with color di1 (Rule 6), at which the agent colors v with 𝖿𝗂𝗇. The only exception occurs when the agent is at the starting node s (with color d0) and no neighbor is colored d1; in that case, the agent terminates the execution (Rule 7).

The following lemma guarantees that the two principles mentioned above are always preserved.

Lemma 8.

During any execution of 𝒜PF5 starting at any node sV, the following two invariants are maintained: (i) the digraph D is acyclic, and (ii) every node assigned a distance color is reachable from the starting node s in D.

Proof.

At the start of exploration, these invariants clearly hold: no node has been assigned a distance color, and consequently D is acyclic. In what follows, we show that none of the rules (i.e., Rules 1,2,…,7) violate these invariants.

The first invariant could potentially be broken only when the agent colors a node v with a distance color via Rules 2 or Rule 3. By the definition of the function f, Rule 2 never creates a cycle in D. Similarly, Rule 3 preserves acyclicity because it is applicable only when v has no neighbor with a distance color, ensuring that no cycle is introduced.

The second invariant could be compromised only when the agent removes a distance color from a node v, as occurs in Rules 6 or Rule 7. However, these rules are applied only when no neighbor of v is colored di+1 (if v is colored di), thus v has no out-going arc in D. Hence, the removal does not disconnect any node from s in D. Therefore, both invariants are maintained throughout the execution.

Lemma 9.

During any execution of 𝒜PF5 on any φ-free graph, Rule 1 is applicable only when the agent is at a node of degree exactly 3.

Proof.

Let v be a node that the agent colors with 𝖿𝗂𝗇 by applying Rule 1 during an execution of 𝒜PF5. For Rule 1 to be applicable at v, the agent must observe all three distance colors d0, d1, and d2 among the neighbors of v. Hence, v must have at least three neighbors.

Assume for contradiction that v has degree at least four. By Rules 1,2, and 3, once the agent visits v, it assigns v either a distance color or 𝖿𝗂𝗇 and never reverts it back to 𝗂𝗇𝗂𝗍. Thus, Rule 1 is applicable at v only during the first visit to v. By Lemma 7, before this first visit, the agent can have visited at most two neighbors of v, so that at most two neighbors have been assigned a distance color. This contradicts the requirement that all three distance colors must be observed at v.

Lemma 10.

Let F denote the set of nodes colored 𝖿𝗂𝗇. During any execution γ0,γ1, of 𝒜PF5 starting at any node sV on any φ-free graph, the induced subgraph G[VF] is always connected.

Proof.

Let F(i) be the set F in configuration γi. Assume for contradiction that there exists an integer i0 such that G[VF(i)] is connected, but G[VF(i+1)]=G[VF(i)]v is disconnected, where v is the node at which the agent is located in γi. We consider two cases, depending on the rule that causes v to be colored 𝖿𝗂𝗇.

Case 1: The agent applied Rule 1 in 𝜸𝒊.

By Lemma 9, v then has exactly three neighbors, and all three must already have been assigned a distance color.

Case 2: The agent applied Rule 6 or Rule 7 in 𝜸𝒊.

In this case, Rule 4 was not applicable in γi, implying that every neighbor of v in N(v)F(i) already has a distance color.

In either case, every neighbor of v in G[VF(i)] has a distance color. By Lemma 8, all these neighbors remain reachable from the starting node s in the digraph D, even after the removal of v. Thus, G[VF(i)]v must be connected, which contradicts our assumption.

Theorem 11.

Algorithm 𝒜PF5=(CPF5,𝗂𝗇𝗂𝗍,ξPF5), which uses five colors, solves the exploration problem on any φ-free graph.

Proof.

We first show that the agent eventually terminates. Notice that the agent changes the color of each node at most twice. Consequently, the rules that alter a node’s color (Rule 1,2,3,6,7) are applied only finitely many times. Moreover, Rule 4 is applied only finitely many times since each application of Rule 4 eventually triggers an application of one of Rule 1,2,3 in the subsequent step. The only remaining rule is Rule 5; however, by Lemma 8, the digraph D remains acyclic throughout the execution, so the agent cannot apply Rule 5 indefinitely. Thus, the agent must eventually terminate.

Now, consider an execution γ0,γ1,,γt of 𝒜PF5 starting at some node sV on a φ-free graph, where at step t1 the agent applies Rule 7 at a node v with distance color di, thereby coloring v with 𝖿𝗂𝗇 and terminating the execution. We claim that v must be the starting node s. Otherwise, by Lemma 8, v would have a neighbor with color di1, contradicting the condition required to apply Rule 7. Hence, the agent terminates at s.

Finally, we show that in the final configuration γt, every node is colored 𝖿𝗂𝗇. In γt, no neighbor of s is colored 𝗂𝗇𝗂𝗍, because the agent does not apply Rule 4 in the step preceding termination. Moreover, no node retains a distance color in γt, since any node with a distance color would be reachable from s in D, yet s has no outgoing arcs in D in the final configuration. Therefore, all nodes must be colored 𝖿𝗂𝗇. By Lemma 10, the induced subgraph G[VF] remains connected, which implies that F=V in γt. This completes the proof.

5 Conclusion

In this paper, we have advanced the study of graph exploration by a single oblivious agent in the recolorable model, originally introduced by Böckenhauer et al. [2]. Our main contributions are twofold:

  • We present a novel exploration algorithm that reduces the color complexity on arbitrary undirected connected graphs from eight to six colors. Moreover, if the graph is triangle-free (i.e., contains no 3-cycles), the color complexity further reduces to five colors.

  • We identify a broad graph class – φ-free graphs, which includes all graphs of maximum degree at most three and all cacti – and show that five colors suffice for exploring every graph in this class.

Several intriguing open problems remain. On arbitrary graphs, no nontrivial lower bound on the number of colors is known, so determining whether six is optimal (or can be further decreased) is a compelling challenge. Moreover, it would be interesting to study how a small amount of internal agent memory – or relaxations such as randomized moves – might impact the color complexity.

References

  • [1] John Augustine and William K. Moses Jr. Dispersion of mobile robots. Proceedings of the 19th International Conference on Distributed Computing and Networking, January 2018.
  • [2] Hans-Joachim Böckenhauer, Fabian Frei, Walter Unger, and David Wehner. Zero-memory graph exploration with unknown inports. In International Colloquium on Structural Information and Communication Complexity, pages 246–261. Springer, 2023. doi:10.1007/978-3-031-32733-9_11.
  • [3] Dominik Bojko, Karol Gotfryd, Dariusz R. Kowalski, and Dominik Pająk. Tree Exploration in Dual-Memory Model. In 47th International Symposium on Mathematical Foundations of Computer Science (MFCS 2022), pages 22:1–22:16, 2022. doi:10.4230/LIPIcs.MFCS.2022.22.
  • [4] Hans-Joachim Böckenhauer, Fabian Frei, Walter Unger, and David Wehner. Zero-memory graph exploration with unknown inports, 2023. doi:10.48550/arXiv.2301.13860.
  • [5] Stefan Dobrev, Paola Flocchini, Giuseppe Prencipe, and Nicola Santoro. Searching for a black hole in arbitrary networks: Optimal mobile agents protocols. Distributed Computing, 19:1–99999, 2006.
  • [6] Stefan Dobrev, Paola Flocchini, Giuseppe Prencipe, and Nicola Santoro. Mobile search for a black hole in an anonymous ring. Algorithmica, 48:67–90, 2007. doi:10.1007/S00453-006-1232-Z.
  • [7] Stefan Dobrev, Nicola Santoro, and Wei Shi. Using scattered mobile agents to locate a black hole in an un-oriented ring with tokens. International Journal of Foundations of Computer Science, 19(06):1355–1372, 2008. doi:10.1142/S0129054108006327.
  • [8] Ajay D Kshemkalyani and Faizan Ali. Efficient dispersion of mobile robots on graphs. In Proceedings of the 20th International Conference on Distributed Computing and Networking, pages 218–227, 2019. doi:10.1145/3288599.3288610.
  • [9] Ajay D Kshemkalyani, Anisur Rahaman Molla, and Gokarna Sharma. Efficient dispersion of mobile robots on arbitrary graphs and grids. arXiv preprint arXiv:1812.05352, 2018.
  • [10] Ajay D Kshemkalyani, Anisur Rahaman Molla, and Gokarna Sharma. Fast dispersion of mobile robots on arbitrary graphs. In International Symposium on Algorithms and Experiments for Sensor Systems, Wireless Networks and Distributed Robotics, pages 23–40. Springer, 2019. doi:10.1007/978-3-030-34405-4_2.
  • [11] Fukuhito Ooshita, Shinji Kawai, Hirotsugu Kakugawa, and Toshimitsu Masuzawa. Randomized gathering of mobile agents in anonymous unidirectional ring networks. IEEE Transactions on Parallel and Distributed Systems, 25(5):1289–1296, 2013. doi:10.1109/TPDS.2013.259.
  • [12] P. Panaite and A. Pelc. Exploring unknown undirected graphs. Journal of Algorithms, 33(2):281–295, 1999. doi:10.1006/JAGM.1999.1043.
  • [13] Vyatcheslav B Priezzhev, Deepak Dhar, Abhishek Dhar, and Supriya Krishnamurthy. Eulerian walkers as a model of self-organized criticality. Physical Review Letters, 77(25):5079, 1996.
  • [14] O. Reingold. Undirected connectivity in log-space. Journal of the ACM (JACM), 55(4):1–24, 2008. doi:10.1145/1391289.1391291.
  • [15] Masahiro Shibata, Toshiya Mega, Fukuhito Ooshita, Hirotsugu Kakugawa, and Toshimitsu Masuzawa. Uniform deployment of mobile agents in asynchronous rings. In Proceedings of the 2016 ACM Symposium on Principles of Distributed Computing, pages 415–424, 2016. doi:10.1145/2933057.2933093.
  • [16] Masahiro Shibata, Daisuke Nakamura, Fukuhito Ooshita, Hirotsugu Kakugawa, and Toshimitsu Masuzawa. Partial gathering of mobile agents in arbitrary networks. IEICE TRANSACTIONS on Information and Systems, 102(3):444–453, 2019. doi:10.1587/TRANSINF.2018FCP0008.
  • [17] Masahiro Shibata, Yuichi Sudo, Junya Nakamura, and Yonghwan Kim. Uniform deployment of mobile agents in dynamic rings. In International Symposium on Stabilizing, Safety, and Security of Distributed Systems, pages 248–263. Springer, 2020. doi:10.1007/978-3-030-64348-5_20.
  • [18] Yuichi Sudo, Daisuke Baba, Junya Nakamura, Fukuhito Ooshita, Hirotsugu Kakugawa, and Toshimitsu Masuzawa. A single agent exploration in unknown undirected graphs with whiteboards. IEICE Transactions on Fundamentals of Electronics, Communications and Computer Sciences, 98(10):2117–2128, 2015. doi:10.1587/TRANSFUN.E98.A.2117.
  • [19] Yuichi Sudo, Fukuhito Ooshita, and Sayaka Kamei. Self-stabilizing graph exploration by a single agent. In 32nd International Colloquium on Structural Information and Communication Complexity (SIROCCO 2025), pages 384–400, 2025.
  • [20] Yuichi Sudo, Masahiro Shibata, Junya Nakamura, Yonghwan Kim, and Toshimitsu Masuzawa. Near-Linear Time Dispersion of Mobile Agents. In 38th International Symposium on Distributed Computing (DISC 2024), pages 38:1–38:22, 2024. doi:10.4230/LIPIcs.DISC.2024.38.

Appendix A The Omitted Proof for Triangle-free Case

Algorithm 4 Graph Exploration Algorithm For Triangle-free graphs 𝒜TF5=(CTF5,𝗂𝗇𝗂𝗍,ξTF5).
Proof of Theorem 5.

In a manner similar to Section 3.2, we define 𝒜TF5=(CTF5,𝗂𝗇𝗂𝗍,ξTF5) and show that 𝒜TF5 simulates semi-DFS on triangle-free graphs.(The definition of 𝒜TF5 is given in Algorithm 4.)

We follow an outline similar to that of Theorem 3.2. First, we redefine the notion of regular, with the modification that we use the term 𝗁𝖾𝖺𝖽 instead of 𝗁𝖾𝖺𝖽𝟣. Let the return path be P=(u1,u2,,uk). Suppose there exists a node uN(uk) that is colored 𝗂𝗇𝗂𝗍. We distinguish between two scenarios based on the value of k.

If k=1, then the node u necessarily belongs to U(P,F). Hence, the agent visits the 𝗂𝗇𝗂𝗍-colored node in accordance with Rule 10 and subsequently recolors it with 𝗁𝖾𝖺𝖽, as prescribed by Rule 4.

If k>1, the agent visits a 𝗂𝗇𝗂𝗍-colored node according to Rule 8. Moreover, if the visited node u belongs to U(P,F), it is recolored with 𝗁𝖾𝖺𝖽; otherwise, it is colored 𝗇𝖾𝗂𝗀𝗁. In either case, the agent returns to uk, following Rule 2 or Rule 3, respectively.

Next, we consider the following two cases:

Case 1: 𝑼(𝑷,𝑭).

Similarly to Theorem 3.2, once a node uU(P,F) is reached, that node is recolored with 𝗁𝖾𝖺𝖽 and the agent returns to uk. Then, following Rules 5 and 13, every node in N(uk) that is colored 𝗇𝖾𝗂𝗀𝗁 is reset to 𝗂𝗇𝗂𝗍, with the agent returning to uk after each reset. Here, the triangle-free property of the graph is crucial: since any node colored 𝗇𝖾𝗂𝗀𝗁 has exactly one adjacent node colored 𝗁𝖾𝖺𝖽, the return destination is uniquely determined. Finally, once all vertices of 𝗇𝖾𝗂𝗀𝗁 have been restored to 𝗂𝗇𝗂𝗍, Rule 6 directs the agent to change the color of uk to 𝗉𝖺𝗍𝗁 and, by moving to u, adds u to P, thereby extending the path.

Case 2: 𝑼(𝑷,𝑭)=.

If k=1, then every node in N(uk) is colored 𝖿𝗂𝗇, and according to Rule 11, the process terminates. In the remaining case where k2, every node in N(uk) that is not colored 𝗉𝖺𝗍𝗁 is recolored with 𝗇𝖾𝗂𝗀𝗁. Moreover, since k2, there is exactly one node adjacent to uk that is colored 𝗉𝖺𝗍𝗁. The agent moves to that node, recolors it with 𝗁𝖾𝖺𝖽, and returns to uk. Afterwards, every node adjacent to uk that is colored 𝗇𝖾𝗂𝗀𝗁 is reset to 𝗂𝗇𝗂𝗍 (again following Rules 5 and 13), and the agent returns to uk. Owing to the triangle-free property of the graph, the unique 𝗁𝖾𝖺𝖽 node to which the agent must return is unambiguously determined. Finally, according to Rule 7, the agent changes the color of uk to 𝖿𝗂𝗇 and returns to uk1.

Therefore, it can be shown that Case 1 simulates the expand operation of the semi-DFS, while Case 2 simulates the remove operation.

Appendix B Model Clarification

As mentioned in Section 1, there is an ambiguity in the original model of [2], specifically in Section 1.2 of that paper: it is unclear whether the agent may recolor a node from a non-initial color back to the initial color. In their description, the rule function – given the current node’s color and the multiset of neighbor colors – outputs a pair (x,y) in the range

{1,2,,nc}×({1,2,,nc}{𝗌𝗍𝗈𝗉}),

where nc is the number of colors excluding the initial color 0. Here, x specifies the new color for the current node, and y specifies which color to move to (or 𝗌𝗍𝗈𝗉 to terminate). However, this range contains a typo: the second component must include 0 so that the agent can move to a node still colored with the initial color, and the first component should also include 0, since Lemma 7 of the arXiv version [4] considers the agent leaving a node colored 0 without changing its color. We therefore conclude that the intended output range in the model of Böckenhauer, Frei, Unger, and Wehner [2] is

{0,1,,nc}×({0,1,,nc}{𝗌𝗍𝗈𝗉}),

which coincides with the rule-function range used in this paper. (As noted in the footnote of Section 2, the 𝗌𝗍𝖺𝗒 option does not extend the model.) Under this corrected interpretation, the agent can indeed recolor a node from a non-initial color back to the initial color.