Manuscript Offprint
arXiv:2610.37783Generating pivot Gray codes for spanning arborescences of complete digraphs and split digraphs in constant amortized time
Abstract
We present the first known efficient algorithm to generate pivot Gray codes for spanning arborescences of complete digraphs, listing all spanning arborescences such that consecutive arborescences differ by reassigning the outgoing edge of exactly one vertex. Our recursive algorithm generates each spanning arborescence in constant amortized time using space. We then extend our algorithm to generate the first known pivot Gray codes for spanning arborescences of split digraphs, achieving constant amortized time per arborescence using space. Finally, we further generalize our approach to proper interval digraphs. When the arborescences are rooted at the leftmost interval, our algorithm generates the pivot Gray code in constant amortized time per arborescence using space.
1 Introduction
A complete digraph (or bidirected complete graph) on vertices, denoted by , is a directed graph (or digraph) in which every pair of distinct vertices is connected by exactly two edges: one in each direction. In other words, for every pair of distinct vertices and , both edges and are present. The underlying undirected graph of a directed graph is the undirected graph on the same vertex set that contains an edge between two vertices if and only if there is at least one directed edge between them in either direction. As such, the underlying undirected graph of is the undirected complete graph (also referred to as a clique), in which every pair of distinct vertices is connected by exactly one undirected edge. For example, the complete digraphs on one to five vertices, that is to are as follows:

Figure 1.1: Complete digraphs from to .

Figure 1.2: The 16 spanning arborescences of rooted at vertex 2.
A spanning arborescence of a directed graph is a subgraph that includes all vertices of and forms a directed tree rooted at some vertex , with all edges directed towards the root. In other words, it is a subgraph of in which there is a unique directed path from every vertex to the root, and it contains no directed cycles. A spanning tree of an undirected graph is a subgraph that includes all vertices of and forms a tree. Throughout this paper, all directed graphs considered in our framework are symmetric digraphs. A symmetric digraph is obtained from an undirected graph by replacing each undirected edge with a pair of oppositely directed arcs. In such symmetric digraphs, every undirected spanning tree admits exactly one valid orientation as an in-arborescence rooted at a fixed vertex . As such, for the symmetric digraphs studied in this paper, a spanning arborescence of corresponds exactly to a spanning tree of the underlying undirected graph . Figure 1.2 illustrates the 16 spanning arborescences of that rooted at vertex 2.
The number of spanning arborescences rooted at a fixed vertex in a complete digraph with vertices is given by Cayley's formula [9]. This is the same as the number of spanning trees in the undirected complete graph , which we can consider the spanning trees of as arborescences rooted at a fixed vertex (say, vertex 1). This enumeration sequence corresponds to sequence A000272 in the Online Encyclopedia of Integer Sequences [30]. For example, the number of spanning arborescences for complete digraphs to rooted at a fixed vertex is 1, 1, 3, 16, 125, 1296, 16807, and 262144, respectively. Cayley provided an informal proof of the formula. Later, Prüfer [31] and Kirchhoff [18] offered simpler proofs by establishing a one-to-one correspondence between spanning trees (spanning arborescences rooted at a fixed vertex) and Prüfer sequences, and by applying the matrix-tree theorem, respectively. More recently, Liu et al. [21] provided a simple one-page proof of Cayley's formula based on their recursive algorithm for generating spanning trees. For more clever proofs of Cayley's formula, see [1].
The study of spanning arborescences in directed graphs and their relatives has a long history and has traditionally attracted considerable interest from mathematicians and graph theorists [1, 6, 9, 10, 12, 18, 19, 22, 26, 27, 29, 31, 34, 35, 38, 39, 42]. The task of efficiently enumerating all spanning arborescences of digraphs is fundamental in computer science and finds applications across diverse scientific fields including epidemiology, networking, chemistry, biology, astronomy, archaeology, image processing, and social media. Notably, in stochastic network analysis, the importance of arborescences is highlighted by the Markov Chain tree theorem originally introduced by Hill in 1966 to model thermodynamic states in biophysics [17]. This theorem expresses the exact stationary distribution of a finite-state directed Markov chain in terms of its spanning arborescences. For more applications on spanning arborescences of digraphs, see [2].
One of the most important aspects of combinatorial generation is to list the instances of a combinatorial object so that consecutive instances differ by a specified closeness condition involving a constant amount of change. Lists of this type are called Gray codes. This terminology is due to the eponymous binary reflected Gray code (BRGC) by Frank Gray [15], which orders the binary strings of length so that consecutive strings differ by one bit. For example, when the order is
0000, 1000, 1100, 0100, 0110, 1110, 1010, 0010, 0011, 1011, 1111, 0111, 0101, 1101, 1001, 0001.
Variations that reverse the entire order or the individual strings are also commonly used in practice and in the literature. For more information about binary reflected Gray code and its variations, see [36, 37, 41]. The BRGC listing is a 1-Gray code in which consecutive strings differ by one symbol change. In this paper, we utilize a generalized version of the binary reflected Gray code to construct Gray codes for spanning arborescences of complete digraphs, split digraphs, and proper interval digraphs.
An interesting problem related to graphs is thus to discover a Gray code for spanning arborescences of digraphs. To address this, we first recall the corresponding notion in the undirected setting. A pivot Gray code for the spanning trees of an undirected graph is a listing of all spanning trees such that consecutive trees differ by a single pivot operation: the removal of one edge and the addition of another edge that shares a common endpoint. For complete graphs, the problem of finding a Gray code for spanning trees of complete graphs was posed as an open problem by Knuth in The Art of Computer Programming, Volume 4 [19] (Ex. 101 in Sec. 7.2.1.6), with a difficulty rating of 46 out of 50:
- Is there a simple revolving-door way to list all spanning trees of the complete graph ? (The order produced by Algorithm S is quite complicated.)
The revolving-door property, as described by Knuth, refers to a Gray code in which consecutive spanning trees differ by the substitution of one edge for another [19]. Smith [40], Merino, Mütze, and Williams [24], and Merino and Mütze [23] provided an edge-exchange Gray code for spanning trees of complete graphs. Notably, Smith's algorithm corresponds to the Algorithm S referenced in Knuth's open problem. Recently, Liu et al. [21] resolved a stronger version of this long-standing open problem of Knuth by constructing the first pivot Gray code for the spanning trees of the complete graph , which can be generated in constant amortized time using space. For example, Liu et al.'s algorithm produces the pivot Gray code for spanning trees of as shown in Figure 1.3.
It is important to note, however, that a pivot Gray code in the undirected setting does not directly translate to the directed setting. While a single undirected pivot replaces one edge with another incident to the same vertex, the corresponding operation in a digraph may

Figure 1.3: Pivot Gray code for spanning trees of by Liu et al.'s algorithm. Only part of the listing is shown.
require reversing the orientation of many edges to maintain a valid arborescence rooted at a fixed vertex. For example, the pivot Gray code generated by Liu et al.'s algorithm requires multiple directed edge changes when applied to digraphs, as the transitions from tree 14 to tree 15, and the transitions from tree 57 to tree 58 in Figure 1.3 for require reversing the orientation of many edges when the arborescences rooted at vertex 1.
We thus require a stricter definition of the pivot operation for spanning arborescences in digraphs. Let be a spanning arborescence of a digraph rooted at . A directed pivot operation transforms into a new valid arborescence by reassigning the unique outgoing edge of exactly one vertex. Formally, , where , , , and remains acyclic. In other words, both the removed and added edges originate from the same vertex , which corresponds to updating the parent pointer of a single non-root vertex. This stricter definition of a pivot change for arborescences in digraphs leads to another open problem regarding spanning arborescence of digraph by Knuth in The Art of Computer Programming, Volume 4 [19] (Ex. 102 in Sec. 7.2.1.6), with a difficulty rating of 46 out of 50:
• Does every directed graph G admit a pivot Gray code on its spanning arborescences rooted at a given vertex?
In fact, generating pivot Gray codes for spanning arborescences is a strictly harder problem. As established earlier, since we focus on symmetric digraphs, any pivot Gray code for spanning arborescences immediately yields a valid pivot Gray code for the underlying undirected spanning trees (by simply ignoring the edge directions).
While pivot Gray codes for undirected spanning trees are known for several important graph classes (e.g., fan graphs, wheel graphs, outerplanar graphs, and recently complete graphs), the situation for directed arborescences is far less developed. In a very recent development, Bonamy et al. [7] proved the existence of a pivot Gray code for spanning arborescences of tournaments (and hence also of complete digraphs). Behroozia and Mütze [3] also proved the existence of a pivot Gray code for spanning arborescences of outerplanar graphs. However, their proofs are purely existential and do not yield an efficient generation algorithm. It is indeed unknown if such a pivot Gray code for spanning arborescences even exists for many other graph classes. In this paper, we address this open problem by providing the first known efficient algorithm that generates a pivot Gray code for spanning arborescences of the complete digraph in constant amortized time using space. We then extend our approach to obtain the first known efficient algorithms that generate pivot Gray codes for

Figure 2.1: The four cases for a pivot change on an edge involving a vertex at level , while preserving the subtree spanning levels 0 to .
spanning arborescences of split digraphs and proper interval digraphs rooted at the leftmost interval in constant amortized time per arborescence using space.
Throughout this paper, we are concerned with the generation of spanning arborescences. Since arborescences are defined on directed graphs, all graphs considered in our computational framework are digraphs. The remainder of the paper is organized as follows. In Section 2, we present a recursive algorithm for generating a pivot Gray code for the spanning arborescences of complete digraphs. In Section 3, we introduce a host-skeleton-routing framework that enables the generation of pivot Gray codes for spanning arborescences of split digraphs. Finally, in Section 4, we further extend this framework to generate pivot Gray codes for spanning arborescences of proper interval digraphs rooted at the leftmost interval.
2.1 Pivot Gray code construction
In the undirected framework in [21], spanning trees are constructed level-by-level and represented by an -tuple , where is the height of the tree rooted at vertex 1. For each level , the string is a -ary string (with , the number of vertices at level ) that encodes the parent connections of the remaining vertices. Here, indicates a connection to the -th vertex at level , while indicates that the vertex is not yet connected at this level. To ensure connectivity, .
A pivot Gray code is obtained by recursively traversing all valid tuples such that consecutive trees differ by a single pivot change. This is achieved by iterating the strings according to a constrained -ary Gray code sequence for each level . The algorithm maintains two sets: , consisting of the vertices at level , and , consisting of the vertices not yet placed in levels 0 through . The parent connections between the candidate vertices in and the active parents in are encoded by a -ary string , where the base accounts for the possible parents in the current level plus the option for a vertex to remain unassigned. If , then all vertices have been placed, so the algorithm outputs the completed spanning tree and returns. Otherwise, it initializes according to the current parent assignments between and , and recursively invokes the generation procedure for level . The algorithm then iteratively updates using a constrained -ary strings Gray code generator (excluding the all-zero string to maintain connectivity). After each update, the algorithm recurses to level to exhaustively generate all valid extensions for the deeper levels. In the undirected setting, the transitions between consecutive -ary strings correspond to four types of pivot changes (cases (a)–(d)) (see Figure 2.1). The first three cases (cases (a)–(c)) correspond to reassigning a single edge. The fourth case (case (d)) occurs when the -ary Gray code generator trying to avoid the all-zero string. This case involves a two-symbol swap (a zero and a non-zero symbol), in which a vertex drops a child and connects to one of its descendants.
A natural approach to generalize this framework to complete digraphs is thus to replace the undirected root (vertex 1) with the designated root of the spanning arborescence, and apply the same level-by-level -ary encoding to encode an arborescence. For example, Figure 2.2 shows the spanning arborescence obtained by rooting the spanning tree at vertex 4, which can be represented by the tuple with the root . While the tuple representation generalizes directly, case (d) transitions might become problematic in the directed setting. When a vertex disconnects from and connects to a descendant of , the ancestor–descendant relationship between and is reversed. Maintaining a valid arborescence then requires reversing the directions of all directed edges along the path from to , resulting in multiple pivot changes. For instance, applying case (d) to the arborescences in Figure 2.2 might attempt to detach vertex 3 from vertex 4 and attach vertex 5 to vertex 4. In the directed setting, this would require reversing the edge to preserve the arborescence property, leading to multiple pivot changes, even though the corresponding move is a valid single pivot change in the undirected setting. Our goal is therefore to eliminate case (d) transitions entirely.
To avoid case (d), we remove all multi-symbol swaps from the underlying -ary string Gray code generator. This is equivalent to constructing a strict 1-Gray code over the set of -ary strings of length that excludes the all-zero string . However, such a 1-Gray code does not always exist from every starting string. For instance, when (binary) and , the valid strings are . Starting at 11 makes it impossible to visit all strings using only single-symbol changes, since moving between 01 and 10 requires a two-bit change. In contrast, starting from a string with exactly one non-zero entry (e.g., 01 or 10) readily admits a valid sequence such as .
Lemma 2.1. There exists a 1-Gray code for the -ary strings of length excluding the all-zero string , starting from any string in which all non-zero digits are distinct, and ending at a string of the form where and for some .
Proof. When (binary case), the statement follows directly from BRGC. The BRGC gener-

Figure 2.2: The spanning arborescence and its rooted tree of that corresponds to the tuple with the root .
ates a 1-Gray code for all binary strings of length . It begins with and ends with . Removing the initial all-zero string yields the desired sequence. For , then the proof is based on the reflectable language framework of Li and Sawada [20], with the modification that we dynamically update the last block of the recursion to force it ends with the string . A detailed proof can be found in Appendix A. A complete Python implementation of our reflectable Gray code generator is provided in Appendix D.
Let be the complete digraph on vertex set . For any nonempty subset , an -forest on is a directed acyclic subgraph of with vertex set such that every vertex has out-degree zero, and every vertex has out-degree exactly one. We say that a -forest is linear if every non-leaf vertex has out-degree exactly one and in-degree at most one. Equivalently, consists of a collection of vertex-disjoint directed paths, each rooted at a distinct vertex in . We denote by the forest induced by considering only the vertices and arcs from level to the maximum depth . For example, the forest corresponding to the spanning arborescence in Figure 2.2 is given by the tuple , which consists of roots and the subtree rooted at vertex 3 containing vertices 5 and 6.
Lemma 2.2. If every string () in the tuple encoding a spanning arborescence has strictly distinct non-zero digits, then the forest induced by the edges in is a linear -forest.
Proof. If all non-zero digits in are distinct, then no two vertices at level share the same parent at level . As such, every vertex at level has in-degree at most one from vertices at level . Since edges only connect adjacent levels, every vertex in the forest induced by the edges in has in-degree at most one. Moreover, because is part of a spanning arborescence, every non-root vertex has out-degree exactly one. A directed acyclic graph in which every vertex has in-degree at most one and out-degree at most one consists of a collection of vertex-disjoint directed paths. Therefore, is a linear -forest.
The idea of linear -forests was first established by Mütze [28], who proved that there exists a pivot Gray code between any two linear -forests on complete graphs, provided that
Algorithm 1 Generating pivot Gray codes for spanning arborescences of complete digraphs
1: procedure GENARB(V, ) 2: where 3: where 4: if then 5: Print spanning tree 6: return 7: 8: for do 9: if then where 10: GENARB(C, ) 11: while GENLINEARK() do 12: 13: if then 14: 15: else 16: 17: 18: GENARB(C, )
their first-level connection strings are distinct (Theorem 14 in [28]). While Mütze's result establishes the structural existence of these Gray codes via the Hamilton-connectedness of flip graphs, our primary objective is to design an explicit, constructive algorithmic framework that physically generates each arborescence in strictly constant amortized time.
To this end, our goal is thus to ensure that every recursive call at level begins with a linear -forest. Then by recursively applying Lemma 2.1, we guarantee that the generation at each level terminates with a string of the form , which resolves the -forest at that level into a single directed path. To maintain the linear -forest invariant across all levels, we refine case (b) from the original undirected framework. In the undirected version, case (b) allows a vertex to disconnect from its parent and reconnect to an arbitrary sibling at the same level. However, if that sibling already has a child, the reconnection creates an in-degree of two, violating linearity. In our directed setting, we require that attaches exclusively to a leaf (a vertex with in-degree zero) of a descendant of a sibling. Since the recursive generation ensures that each subtree collapses into a directed path by the time the 1-Gray code -ary strings are exhausted, attaching to a leaf simply extends an existing path without introducing branches. Applying this leaf-attachment rule recursively guarantees that every intermediate forest remains linear throughout the generation process. Pseudocode for this spanning arborescences generator is given in Algorithm 1. For the sake of clarity, the algorithm is presented in its conceptual base form. It can be optimized to run in strictly constant amortized time per generated arborescence by applying the optimizations described in [21]. To run the algorithm, we make the initial call GENARB({1,2,3,...,n}, ) which sets , and . The complete details of the constant amortized time optimization, along with a full Python implementation, are provided in Appendix C. The spanning arborescences of generated by GENARB are listed in Appendix B.
Theorem 2.3. The algorithm GENARB generates a pivot Gray code for spanning arborescences of complete digraphs .
Proof. The algorithm begins with the linear chain , which is a linear forest. At each level , after updating , the algorithm recursively exhausts all valid extensions for levels to . By Lemma 2.1, these deeper levels always terminate in a linear configuration. Cases (a) and (c) only reassign a parent pointer at level and do not affect the structure of the forest , so the -forest remains linear. For case (b), a vertex at level is detached and reattached at a deeper level. Since is linear prior to this move, the component containing is a single directed path. The algorithm attaches to a leaf of another path, which certainly would not create any vertex of in-degree two. Thus, the forest remains linear after the transition. By induction, the -forest induced from each level to level remains linear.
We then prove by contradiction that our algorithm exhaustively generates every spanning arborescence. Suppose there exists a valid arborescence encoded by a tuple with a specific root that is missing from the listing. By Lemma 2.1 and GENLINEARK, the absence of implies that the prefix never appears in the generation at level . Recursively applying the same argument implies that no spanning arborescence at level zero matching . However, at level zero, GENARB generates a 1-Gray code (via GENLINEARK) that includes all binary strings except , covering all possible for spanning arborescences of , a contradiction.
Theorem 2.4. Spanning arborescences of complete digraphs with n vertices can be generated in pivot Gray code order in constant amortized time per tree, using space.
Proof. The 1-Gray code for k-ary strings can easily be generated in constant amortized time using linear space via the reflectable framework in [20]. Most of the other operations in GENARB can be completed in constant time using linear space, except for case (b), where finding the leaf of a path takes time, where j is the length of the path being extended (see Appendix C for implementation details using child pointers). However, this cost is amortized: extending the path by j levels immediately triggers recursive calls that generate at least one new arborescence at each of the deeper j levels. As such, the algorithm runs in constant amortized time per arborescence, using linear space.
Finally we provide a useful corollary which will become handy when we discuss split digraphs and proper interval digraphs in the subsequent sections.
Corollary 2.5. The algorithm GENARB begins and ends with a linear spanning arborescence, that is, a single directed path in which every vertex except the root has exactly one parent.
Proof. The algorithm initializes with the linear chain . By Lemma 2.1, every recursive call terminates with a string of the form for some , which encodes a single directed path. Therefore, the final arborescence generated by the algorithm is linear.

Figure 3.1: A split digraph with a clique and an independent set containing the vertices .
3 Spanning arborescences of split digraphs
This section presents a pivot Gray code for spanning arborescences of split digraphs. A graph is a split graph if its vertex set can be partitioned into a clique and an independent set . The symmetric split digraph is obtained by replacing each undirected edge with a pair of symmetric directed edges. For example, Figure 3.1 shows a split digraph consisting of a clique on five vertices and an independent set with vertices . Without loss of generality, we assume that the clique is a maximal clique, that is, no vertex in the independent set is adjacent to every vertex in the clique. We also assume that the underlying split graph is connected; equivalently, every independent-set vertex has at least one neighbor in the clique.
Split graphs form an important subclass of chordal graphs. In fact, as the number of vertices , the proportion of chordal graphs that are split graphs approaches one [4]. As such, an efficient algorithm for generating spanning arborescences of split digraphs essentially solves the problem for almost all chordal digraphs in the asymptotic sense. Split graphs have long attracted significant attention due to their rich structural and algorithmic properties [14, 16, 25, 33, 43]. For instance, while fundamental optimization problems like maximum independent set, minimum clique cover, and graph coloring are NP-hard on general graphs, they admit elegant linear-time algorithms on split graphs (and more generally, on chordal graphs) via simplicial elimination orderings [13]. Furthermore, split graphs serve as a vital tractability boundary: the cluster deletion problem, which remains NP-complete even on restricted subclasses of chordal graphs, becomes solvable in polynomial time when restricted to split graphs [8]. These tractability results stem from the simple clique-independent set partition, which also yields a clean forbidden-subgraph characterization: split graphs are precisely the graphs containing no induced , , or [11]. Despite these nice properties of split graphs, it was not previously known whether split graphs admit a pivot Gray code for their spanning trees (or spanning arborescences for their digraphs counterpart). We resolve this question affirmatively by constructing the first pivot Gray code for spanning arborescences of split digraphs. Our construction builds directly upon the framework developed for complete digraphs in the previous section.
The main idea of our algorithm is to decompose a spanning arborescence of a split digraph into three combinatorial components: the host, the skeleton, and the routing. Let the independent set be ordered as . For each independent vertex , we define its set of out-neighbors in the clique (i.e., the vertices in to which has a directed edge) as , where denotes the set of directed edges of the digraph. We first assume the root lies in the clique . The case where the root lies in the independent set will be discussed later in this section. We then demonstrate that every spanning arborescence of a split digraph rooted at a clique vertex can be uniquely represented by a tuple , where is the root in the clique , with , , and defined as follows.
-
Host (): The host mapping determines the outgoing edges from the independent set . In any spanning arborescence rooted at , every vertex has exactly one outgoing edge directed to a vertex in . The host configuration is represented by a parent mapping , which determines the outgoing edges from the independent set . In any spanning arborescence rooted at , every vertex has exactly one outgoing edge directed to a vertex in , denoted . We encode the host mapping as a mixed-radix string , where the digit is an index indicating that is the -th smallest vertex in the neighborhood .
-
Skeleton arborescence (): Since the original structure is a spanning arborescence, is itself a spanning arborescence of the complete digraph rooted at . Every vertex has exactly one outgoing edge in the arborescence. This edge either points directly to another clique vertex or to an independent vertex . In the latter case, the path continues from to . We define the skeleton as the projection of these connections onto the clique . Formally, an edge exists if the arborescence contains either the direct path , or a path for some which we denote as an alias path.
-
Routing (): While the skeleton determines the connectivity within the clique, the routing specifies the actual edges used in to connect the clique vertices. For each edge in the skeleton , vertex may connect to either directly or via an independent vertex acting as an “alias” (similar to how a computer network works). For a fixed host , the set of valid aliases for is
The routing choices for all are encoded by a mixed-radix string , where for each the symbol . If , then connects directly to via the clique edge . If , then routes through the -th smallest vertex in .
Lemma 3.1. Let be a split digraph with root . There is a bijection between the spanning arborescences of rooted at and the valid tuples .

Figure 3.2: A spanning arborescence of the split digraph in Figure 3.1 represented by the tuple .
Proof. We show that the mapping is both injective and surjective.
(Arborescence Tuple): Let be any spanning arborescence of rooted at . Since is an independent set, every vertex has out-degree exactly one, and its unique out-neighbor lies in . This uniquely determines the host string .
For each , the unique outgoing edge from in either goes directly to some or to some such that . In both cases, it induces a unique logical edge in the skeleton . Moreover, must be acyclic, because any directed cycle in would induce a directed cycle in , a contradiction. Thus, is a valid spanning arborescence on . The specific edge chosen (direct or via alias) uniquely determines the routing symbol . Thus, each arborescence maps to exactly one valid tuple.
(Tuple Arborescence): Conversely, consider any valid tuple . The host string assigns exactly one outgoing edge from each vertex in to a vertex in . The skeleton together with the routing string assigns exactly one outgoing edge to each vertex in . This construction yields exactly edges. Since is a spanning arborescence on rooted at , every vertex in has a directed path to . Every vertex in has a path to because it points to some vertex in (via ) and all vertices in reach . Furthermore, every non-root vertex has out-degree exactly one, with all paths directed toward the root. The resulting digraph is thus acyclic and is a spanning arborescence of rooted at . Finally, different tuples produce different sets of edges, so the mapping is injective.
Example of the tuple encoding (Figure 3.2): Consider a split graph with clique and independent set . The spanning arborescence shown in Figure 3.1 can be represented by the tuple and is interpreted as follows:
• Root: .
-
Host (): Vertex 6 connects to the first available neighbor in (vertex 1), vertex 7 to its first (vertex 2), and vertex 8 to its second (vertex 4).
-
Skeleton (): This tuple defines a spanning arborescence on (generated via the complete digraph framework in Section 2).
-
Routing (): Among the four non-root clique vertices, only vertex 2 uses an alias (), routing through its available independent vertex (vertex 6). The remaining vertices use direct clique edges.
3.1 Spanning arborescences rooted at a vertex in the clique
Since the tuple uniquely encodes every spanning arborescence rooted at , generating a pivot Gray code reduces to the problem of traversing the space of valid tuples such that each consecutive tuple differ by a pivot change. We achieve this with a three-stage nested generator that iterates over the host , skeleton , and routing components .
-
Host generator (): The outermost loop enumerates all valid parent assignments from the independent set to the clique . Since is a mixed-radix string, we generate it using a reflectable 1-Gray code described in [20]. Each transition changes the parent of exactly one vertex in , that is one pivot change.
-
Skeleton generator (): For a fixed host configuration , the middle layer generates spanning arborescences on the clique using the spanning arborescence pivot Gray code generator for complete digraphs (see Section 2 and Algorithm 1). The fixed alias paths induced by are treated as valid routing options inside the skeleton generation.
-
Routing generator (): For each fixed host and skeleton , the innermost layer generates the actual routing choices using another reflectable mixed-radix 1-Gray code. Each step changes the routing decision (direct edge vs. alias) for exactly one clique vertex, that is one pivot change.
Pseudocode of this three-stage nested generator is given in Algorithm 2. The algorithm GENSPLITARB begins by initializing the baseline routing options for each clique vertex based on the edges between the clique and the independent set . The outermost generator, GENHOST, iterates over all host configurations , dynamically updating the available routing options after each host change. Then for each fixed host configuration, it invokes the middle-layer skeleton generator GENARB to enumerate spanning arborescences on the clique . For each generated skeleton , the function GETROUTINGMIXEDRADIX computes the valid routing aliases. Finally, the innermost generator GENROUTING cycles through these routing options. At the deepest level of recursion, the tuple is decoded into a spanning arborescence of the split digraph.
Note that, however, naïve nesting of this algorithm might create cycles when we finish generating the routing choices . When the host generator is about to change the parent of an independent vertex , some clique vertices (for example, ) may currently use as an alias.
Algorithm 2 Generating pivot Gray codes for spanning arborescences of split digraphs
1: procedure GENSPLITARB() 2: 3: for do 4: Update 5: for do 6: 7: for do 8: yield decode arborescence
If the new parent of is one of those clique vertices, the update would introduce a directed cycle (e.g., ), thereby violating the arborescence property. To prevent this, we must ensure that immediately before updating , no clique vertex is using as a routing alias. We achieve this through a look ahead mechanism that identifies the upcoming host independent set vertex that is going to be updated, and applies endpoint control in the inner generators. This is achieved by modifying the GENHOST function to explicitly identify the independent vertex scheduled for the next pivot and passes it as a parameter to the skeleton generator GENARB, which enables the routing generator to safely orient its terminal states, as formalized in the following lemma.
Lemma 3.2. Let be the independent vertex scheduled to pivot next, and let be the final skeleton arborescence generated in the current host block. If is a single directed path rooted at , then regardless of the current routing configuration, the nested generation of the skeleton and routing aliases can be dynamically controlled to terminate in a configuration where no vertex in utilizes as an alias (i.e., for all ).
Proof. Let be the current host of . Since is a single path, every vertex has at most one child. In particular, has at most one child in , which we denote as . Since a clique vertex can only route through if its skeleton parent is , is the only vertex in the entire clique capable of using as an alias at the end of the generation of the skeleton arborescence. If no such exists (either is a leaf or the edge does not exist), then is unavailable as an alias for all , and the claim holds immediately.
Now assume exists. Its available routing options contain both the direct choice and the alias . Our goal is to force the terminal routing value of to be the direct choice , ensuring that the subsequent update of the host vertex does not disrupt the skeleton arborescence. We prove that the nested generation of always offers an opportunity to reset the parity of the reflectable routing generator, safely setting to the direct path at the end of the generation of .
If has only two vertices and an exists in the independent set allowing , can form a larger clique, violating the assumption that is maximal. Now consider has at least three vertices. Such a reset opportunity must exist as the last arborescence includes and there exists an arborescence without . One of the reset opportunities arises when the skeleton edge is going to be established for the final time prior to (meaning the path will remain connected until the skeleton block concludes). Such an opportunity always exists since the edge is present in the terminal arborescence . At this point, has at least two routing choices: the direct path or the alias path . The routing generator operates as a reflectable mixed-radix Gray code. Thus, for every subsequent skeleton arborescence generated, the routing cycle for will be reflected: becomes , or vice versa. The final state of is therefore completely determined by its initial state and the parity of the number of remaining skeleton configurations, once we place at the first level of the reflectable recursion tree of the routing generator. Therefore, if we know how many arborescences we still need to generate (this value can be computed by exhaustive search, look ahead, or precomputation), then we can set to the direct path if the parity of the remaining sequence is even, and to the alias (or another extreme) if the parity is odd. As such, as the algorithm exhausts the remaining arborescences in the skeleton block, the reflectable routing generator completes its sequence and comes to rest on the direct path . This way, when we reach , will always use the direct path , and we can safely pivot the host vertex .
The next natural question is how to determine when the skeleton edge is established for the final time prior to reaching , and how to efficiently compute the parity of the remaining arborescences. It turns out that, by exploiting the linear property of , both values can be computed efficiently.
Lemma 3.3. If is a single directed path rooted at , then the exact step when the skeleton edge is established for the final time prior to reaching and the parity of the remaining skeleton arborescences can be identified and computed in constant time.
Proof. Since is a single directed path, the string at each level of the skeleton ends with a single-child configuration of the form . Without loss of generality, assume the final string at level is , where is the number of unassigned vertices at that level. We now trace how the final skeleton edge is established.
The vertex is a parent passed from the previous level (or is the root). We first analyze the general case where . Since is a single directed path, level contains only the vertex . Thus, the 1-Gray code generator uses BRGC to exhaustively generate the valid constrained binary strings of length , excluding . The digit 1 in the terminal string corresponds to the edge . The final three strings of the BRGC sequence are , , and . Therefore, the edge is established for the final time at the transition to , which can be identified by observing that exactly two strings remain in the BRGC sequence.
We then compute the total number of remaining skeleton arborescences. The number of remaining skeleton arborescences correspond to the spanning forests on vertices extending the states ( roots) and ( root). By the generalized Cayley's formula for forests, the number of spanning forests on vertices with specified roots is . Thus, the total number of remaining skeleton arborescences is
Algorithm 3 Generating pivot Gray codes with routing alias control
1: procedure GENARB(V, , x, last) 2: where 3: where 4: if then yield 5: 6: Initialize parents mapping to P 7: 8: GENARB(C, , x, last ) 9: 10: while GENLINEARK( , ) do 11: 12: 13: if then 14: 15: else 16: 17: 18: if last and and then 19: if is even then 20: 21: else 22: 23: else if last and and and then 24: 25: else 26: 27: GENARB(C, , x, last ) 28:
endpoint control
Taking this modulo 2, the parity of the remaining arborescences simplifies to . Finally, when , the local sequence reduces to the single-state string , indicating that we have reached . Thus, the parity of the remaining global sequence is exactly the parity of in both cases, which can be computed in constant time.
Pseudocode for the updated spanning arborescence generator is provided in Algorithm 3. The procedure extends Algorithm 1 (for complete digraphs) by incorporating dynamic routing assignments and endpoint control required for split digraphs. To track the precise timing of block boundaries, the algorithm uses two state variables: a boolean last flag and a countdown variable . The last flag is propagated down the recursion tree and becomes true when all previous recursive levels have reached their final configurations. The variable tracks the number of remaining skeleton configurations at the current level. By monitoring these variables, the algorithm identifies the exact transition at which the terminal skeleton edge is established. The routing alias initialization is then overridden when last is true and equals 2 or 1. At these points, the algorithm detects the formation of . We then assign to the first level of the routing generator's reflectable recursion tree and initialize the coordinate according to the parity of c. To generate the complete sequence of spanning arborescences for a split digraph, we make the initial call GENSPLITARB( ). This procedure then coordinates the nested traversal by invoking GENHOST, the updated GENARB, and GENROUTING to resolve the alias assignments. A complete Python implementation of the algorithm is provided in Appendix E.
As an example, the 21 spanning arborescences of the split digraph from Figure 3.1, rooted at vertex 1, are listed in Figure 3.3. Endpoint control is applied at the underlined arborescences 10 and 16 to force the active clique vertices to use their direct skeleton edges immediately before the host transitions of the independent vertices. In the case of Tree 10, the last flag is set to true and . Here, the independent vertex scheduled to pivot its host is vertex 4, and the skeleton generator pivots the edge to (i.e., u = 2 and p = 1). At this point, as the skeleton edge of is being established, vertex 2 can either connect directly to its skeleton parent 1 or route through the alias path via the independent vertex 4. Since indicates that exactly two skeleton configurations remain in the current block, the algorithm initializes the routing state of vertex 2 to the direct path . The reflectable routing generator then traverses the available routing choices, pivoting from the direct path to the alias path (Tree 11). In the next step, the skeleton generator transitions to the final arborescence of the block by pivoting vertex 3 to vertex 2 (Tree 12). At this stage, the routing generator is reflected, causing the active path to pivot from the alias back to the direct path (Tree 13). As such, no clique vertex utilizes vertex 4 as an alias, allowing the independent vertex 4 to safely change its host to vertex 2 in the subsequent step (Tree 14). Then in the case of Tree 16, the last flag is set to true and . Here, the independent vertex scheduled to pivot its host is vertex 5, and the skeleton generator pivots the edge to (i.e., u = 2 and p = 3). At this point, the skeleton edge of is being established, vertex 2 can either connect directly to its skeleton parent 3 or route through the alias path via the independent vertex 5. Since indicates that only one skeleton configuration remains in the current block, the algorithm initializes the routing state of vertex 2 to the alias path . The reflectable routing generator then traverses the available routing choices, pivoting from the alias path to the direct path (Tree 17). As such, no clique vertex utilizes vertex 5 as an alias, allowing the independent vertex 5 to safely change its host to vertex 2 in the subsequent step (Tree 18).
Theorem 3.4. The algorithm GENSPLITARB generates a pivot Gray code for the spanning arborescences of a split graph rooted at a vertex .
Proof. By Lemma 3.1, there is a bijection between the spanning arborescences of rooted at and the valid configuration tuples . The algorithm decomposes the generation into three nested layers corresponding exactly to these components: the host assignments for vertices in , the skeleton arborescence on the clique , and the routing aliases . The host assignments and the skeleton are strictly independent; the structure

Figure 3.3: The pivot Gray code sequence of spanning arborescences for the split digraph in Figure 3.1, rooted at vertex 1. Endpoint control is applied at the underlined arborescences 10 and 16 to force the clique vertices to use their direct skeleton edges immediately before the host transitions of the independent vertices.
of imposes no restrictions on . Furthermore, while the available option for the routing aliases depends on the current host configuration , the specific routing options made by the innermost loop do not affect the validity of or . Since these routing options are independent and each nested generator exhaustively enumerates every valid string in its domain exactly once, the overall procedure generates every valid tuple exactly once. As such, it produces every spanning arborescence of exactly once.
Within each individual generator (host, skeleton, and routing), the traversal is a 1-Gray code, which translates to a pivot change. For both the routing generator and the skeleton generator, each step translates directly to a valid single-edge pivot change and introduces no cycles, thereby preserving the arborescence property. The only potential threat to the arborescence property occurs at host block boundaries, when the outer host generator changes the parent of an independent vertex . If some clique vertex were using as a routing alias at that moment, multiple parent pointers would change simultaneously. However, by Lemma 3.2, the nested generators employ endpoint control to ensure that the routing configuration terminates in a state where no vertex uses as an alias ( for all ). Since the routing is safely using the direct skeleton edges, the host transition modifies only the single outgoing edge from . Thus, both internal transitions and boundary transitions correspond to a valid single pivot change. Since the algorithm visits every spanning arborescence exactly once and every consecutive pair differs by a single pivot change, the resulting listing is a pivot Gray code.
Theorem 3.5. Spanning arborescences of split graphs can be generated in a pivot Gray code order in constant amortized time per arborescence, utilizing space when rooted at a vertex in the clique.
Proof. By Theorem 2.4, spanning arborescences of can be generated in constant amortized time per arborescence using space. The reflectable mixed-radix Gray codes used for the host assignments () and routing aliases () can be generated in constant amortized time per string. The only operation that may exceed constant time is thus the transition at the host level. When an independent vertex changes its host in , the algorithm updates the routing mapping tables (i.e., the available aliases for clique vertices). This update takes time by maintaining a global routing table throughout the execution, and updates only the aliases associated with the neighborhood of the moving vertex. However, once the update is complete, the inner skeleton generator produces at least spanning arborescences, which amortizes the hosting update time to constant time per generated arborescence. The endpoint control mechanisms that include checking alias availability and computing the parity of the remaining skeleton arborescences can be performed in constant time by Lemma 3.3. Finally, for space complexity, the algorithm maintains adjacency mappings, parent pointers, and alias routing tables, which can all be maintained using at most space. Therefore, the algorithm achieves constant amortized time per arborescence, using space.
3.2 Spanning arborescences rooted in the independent set
We now consider the case where the designated root belongs to the independent set . The key difference is that is adjacent only to a subset of the clique. In any valid spanning arborescence rooted at , all paths to the root must pass through . As such, the set of vertices in that choose as their parent must form a non-empty subset . Once is fixed, the remaining vertices induce a spanning forest rooted at . Since is a clique, this subproblem reduces to the complete-digraph spanning arborescence generation framework. We handle this structure by treating as the root of the skeleton arborescence , while restricting its possible incoming edges. In the standard complete digraph setting, the first level string has length . When , we instead use a binary string of length , where each bit indicates whether the corresponding vertex in points directly to . To ensure connectivity, we similarly require that . Since belongs to the independent set, it requires no routing decision. After fixing , the generation of the remaining skeleton edges within and the parent assignments for the remaining independent vertices proceeds identically to the clique-rooted split graph case. Since the restricted sequence is generated using BRGC, all transitions correspond to single pivot changes. As an example, the split graph in Figure 3.1 can be decomposed into the three components (host, skeleton, and routing) as shown in Figure 3.4 when rooted at the independent vertex 6. A complete Python implementation of the updated algorithm GENSPLITARB for the case where the root lies in the independent set is provided in Appendix E.
Theorem 3.6. The modified algorithm GENSPLITARB generates a pivot Gray code for the spanning arborescences of a split graph rooted at a vertex .
Proof. Any spanning arborescence rooted at must have a non-empty set of incoming edges from a subset , where is the set of neighbors of in the clique. The remaining

Figure 3.4: The host, skeleton, and routing components of the split digraph from Figure 3.1 when rooted at the independent vertex 6. Note that the independent vertex 6 is now treated as the root of the skeleton block. Since the root is non-adjacent to the clique vertices 4 and 5, the first-level connection string of the skeleton arborescence is restricted to the neighborhood .
vertices in induce a spanning forest rooted at . The modified algorithm GENSPLITARB thus captures this structure by replacing the standard first level string , where each bit indicates whether the corresponding vertex in points directly to . Since the algorithm exhaustively enumerates all valid choices of and pairs them with the complete generation of the remaining skeleton forest on together with the host and routing assignments for , it produces every spanning arborescence exactly once.
Within the modified base level, is generated using BRGC excluding the all-zero string. Thus, consecutive configurations of differ by exactly one bit, corresponding to a single pivot change. This modification at the root level does not interfere with the endpoint control mechanisms used for the remaining independent vertices, since cannot serve as a host or routing alias. The analysis of the rest of the host and routing transitions follows identically to that of Theorem 3.4. Therefore, consecutive arborescences in the generated sequence differ by exactly one pivot change, yielding a pivot Gray code.
Theorem 3.7. Spanning arborescences of split graphs can be generated in a pivot Gray code order in constant amortized time per arborescence, utilizing space when rooted at a vertex in the independent set.
Proof. The modified base level , which encodes the subset of directed edges from the neighborhood to the root , is generated using BRGC which can be done in constant amortized time per string. The remainder of the algorithm operates identically to the clique-rooted case and thus the algorithm generates each spanning arborescence in constant amortized time, using space.
Together, Theorems 3.4, 3.5, 3.6, and 3.7 establish the following result.
Theorem 3.8. Spanning arborescences of split graphs can be generated in a pivot Gray code order in constant amortized time per arborescence, using space.
4 Spanning arborescences of proper interval digraphs
It is worth noting that our host-skeleton-routing framework is not restricted to split digraphs. In fact, it is quite versatile and can potentially be extended to broader classes of digraphs whose structure can be decomposed into connections of cliques. We demonstrate the power of this framework by extending it to generate pivot Gray codes for spanning arborescences of proper interval digraphs rooted at the leftmost interval.
A proper interval graph is the intersection graph of a family of intervals on the real line such that no interval properly contains another. The symmetric proper interval digraph is obtained by replacing each undirected edge with a pair of symmetric directed edges. By Roberts' theorem [32], proper interval graphs are equivalent to unit interval graphs (where all intervals have equal length) and indifference graphs. Due to their highly regular structure, proper interval graphs play a central role in numerous applications, including chronobiological time-series analysis, task scheduling with uniform processing times, and physical mapping of DNA sequences in bioinformatics [5, 14]. Proper interval graphs admit a canonical layered partition obtained via breadth-first search (BFS). Given a proper interval representation, let be the interval with the leftmost left endpoint (which also has the leftmost right endpoint). We designate as the root. The vertex set can then be uniquely partitioned into BFS layers with respect to , where and, for ,
with denoting the length of the shortest path from to in . These layers satisfy the following properties:
-
Each forms a clique;
-
There are no edges between non-consecutive layers (i.e., edges exist only within the same layer or between adjacent layers);
-
For each , there exists a vertex adjacent to every vertex in .
This layering respects the natural left-to-right order of the intervals and satisfies a strong local domination property: for each , the vertex dominates (i.e., ), and the set induces a clique. As an example, Figure 4.1 shows a proper interval digraph on 11 vertices, together with its interval representation and its layer partition.
We construct a pivot Gray code for spanning arborescences of proper interval digraphs rooted at by recursively applying our host-skeleton-routing framework in an inductive, layer-by-layer manner. Let denote the induced subgraph of a proper interval digraph on the vertices in layers . Given a pivot Gray code for the spanning arborescences of , we construct the pivot Gray code for by treating the previously solved subgraph as the skeleton and the newly appended layer as the host. We show that every

Figure 4.1: A proper interval digraph with an interval representation and the associated layer partition.
spanning arborescence of rooted at can be uniquely represented by the tuple .
-
Host (): The host mapping determines the parent assignments for all vertices in the newly added layer . Unlike the independent set in a split digraph, the vertices of induce a clique. For any valid spanning arborescence of rooted at , every vertex in must eventually reach the root via the predecessor layer . To achieve this, the vertices in must choose parents such that they form a spanning forest rooted at some non-empty subset . Note that this structure differs slightly from the standard -forest defined on a single vertex set, as the target roots lie outside and a vertex in is not necessarily to connect to all vertices in . In contrast to split digraphs, a vertex in need not connect directly to ; instead, it may connect internally within the clique , with only the local roots of this forest making the jump to . We refer to this family of directed trees spanning as the host forest .
-
Skeleton (): The skeleton is a spanning arborescence of the subproblem (the proper interval digraph induced by layers through ). Since is itself a proper interval digraph of smaller depth, its spanning arborescences are generated recursively by the algorithm from the previous step. The skeleton provides the global routing paths to the root for all vertices in the deeper layers.
-
Routing (): The routing determines whether a vertex connects directly to its skeleton parent in , or utilizes a vertex as an alias to route its path through the new layer. Since induces a clique with possible internal connections, this alias path may traverse multiple vertices within before returning to the skeleton.

Figure 4.2: A spanning arborescence for the first four layers in Figure 4.1 represented by the tuple .
Lemma 4.1. Let be the induced proper interval subgraph containing layers with root . There is a bijection between the spanning arborescences of rooted at and the set of valid configuration tuples .
Proof. The proof follows that of Lemma 3.1, with the necessary adaptations to the layered structure of proper interval graphs. We replace the host mapping for split digraphs with a rooted spanning forest on whose roots lie in . Furthermore, instead of single-edge aliases as in split digraphs, each routing choice (for ) now indexes a vertex in that serves as the entry point of a directed path in terminating at the skeleton parent in . Such a path is unique given is a forest. The acyclicity, connectivity, and uniqueness arguments from Lemma 3.1 carry over directly under this host-skeleton-routing definition, establishing the bijection.
Lemma 4.2. Let be the proper interval subgraph restricted to layers . There is a bijection between the spanning arborescences of rooted at and the sequence of tuples , where each denotes the skeleton, host forest and routing aliases at layer .
Proof. We proceed by induction on . The base graph possesses only the empty arborescence. Assume by induction that the spanning arborescences of are in bijection with the nested configurations . By Lemma 4.1, the spanning arborescences of are in strict bijection with the tuples . Substituting the inductive assumption for the skeleton yields the bijection for .
Example of the tuple encoding (Figure 4.2): Consider a proper interval digraph formed by the first 4 layers in Figure 4.1. The spanning arborescence can be represented by the tuple where the first three layers form the skeleton .
-
Root: .
-
Host (): The host forms a forest in which vertices 4 and 5 in act as roots. Vertex 6 connects to the first available root in (vertex 4), and vertex 8 connects to the only available root (vertex 5). Vertex 7 then connects to the first available parent in (vertex 6).
-
Skeleton (): The skeleton is a spanning arborescence of .
-
Routing : Only vertex 5 in uses an alias path ( with its available routing options {4, 6, 7}).
We first prove the following lemmas for the pivot Gray code for the host generator.
Lemma 4.3. There exists a 1-Gray code for the mixed radix strings of length excluding the all-zero string , starting from a legal string , and ending at a legal string of the form where , , and for some .
Proof. Such a Gray code can be constructed by modifying the standard reflectable Gray code framework of Li and Sawada [20]. We first apply a permutation to the radices, moving those with even values to the top levels of the recursive generation tree and relegating those with odd values to the bottom. A detailed proof can be found in Appendix A.
Lemma 4.4. If all vertices in form a linear arborescence with one root in the first host configuration, then they also form a linear arborescence with one root in the last host configuration.
Proof. The result follows immediately from Lemma 2.1 and Lemma 4.3.
From this we obtain the following corollary.
Corollary 4.5. Let and be the first and last spanning arborescences in the pivot Gray code for . Then the vertices in form linear arborescences in both and .
The pivot Gray code for the routing component can be handled similarly using the reflectable language framework. Note, however, that dynamic endpoint control is also required when the host generator is about to pivot a vertex that is not directly connected to , but serves as the root of an alias vertex.
Lemma 4.6. Let be the vertex scheduled to pivot next by the host generator, and let be the final arborescence of . Then the nested skeleton and routing aliases can be dynamically controlled to terminate in a configuration where no vertex in utilizes any vertex in the subtree rooted at as an alias.
Proof. The proof generalizes the endpoint control established in Lemma 3.2. In a split digraph, an independent vertex affects only itself. In a proper interval digraph, the vertices of form a host forest . When pivots its connection to , it carries its entire subtree with it. If any vertex utilizes a vertex as an alias, a cycle might occur violating the arborescence property. Thus, we must ensure that every vertex with an alias path involving any vertex in ends on a direct path. Since the pivot Gray code for ends with a linear arborescence, the same reset opportunities used in Lemma 3.2 can be used to force all affected vertices in to terminate on direct paths.
Lemma 4.7. Given a pivot Gray code for the spanning arborescences of and for the host layer , the host-skeleton-routing framework generates a pivot Gray code for the spanning arborescences of .
Proof. The proof follows that of Theorem 3.4. The host, skeleton, and routing components are independent, and each nested generator exhaustively enumerates every valid string in its domain exactly once. Thus, the overall procedure generates every valid tuple exactly once. Within each generator, the traversal is a 1-Gray code, corresponding to a single pivot change. Endpoint control, as established by Lemma 4.6, ensures that the routing configuration terminates in the direct paths where no vertex uses any vertex in the relevant subtree as an alias. Therefore, the listing forms a pivot Gray code.
Recursively constructing from layer to results in the following theorem.
Theorem 4.8. The host-skeleton-routing framework generates a pivot Gray code for the spanning arborescences of proper interval digraphs rooted at the leftmost interval.
Lastly, we consider the time complexity of our algorithm. Unlike complete graphs, there is no simple formula to compute the remaining number of arborescences on the fly for proper interval digraphs. Nevertheless, we achieve constant amortized time per arborescence via a two-pass simulation technique.
Theorem 4.9. Spanning arborescences of proper interval digraphs can be generated in a pivot Gray code order in constant amortized time per arborescence, utilizing space, provided the root is the leftmost interval .
Proof. The majority of the operations follow the implementation logic developed for split digraphs. The primary difference occurs at the host block boundaries, when a host vertex in applies a pivot change.
In this scenario, the algorithm must first update the routing alias mapping table. In split digraphs, this took time. In proper interval digraphs, we must verify whether the neighbors of the pivoting vertex possess valid directed paths into . This path verification and alias update requires at most time. However, this setup cost is incurred only at the boundary of a host block. Immediately following this update, the algorithm traverses the inner domains of the skeleton and routing configurations. Since this inner generation produces a number of arborescences that strictly dominates the polynomial setup cost (or is bounded by a trivial constant in base cases), the host update mathematically amortizes to constant time per generated arborescence.
Then, the dynamic endpoint control needs to determine the parity of the remaining sequence. Rather than relying on heavy algebraic precomputation, we achieve this via a two-pass simulation technique. For a fixed host configuration, the algorithm first executes a “simulation” pass of the skeleton generator. During this initial pass, the algorithm does not evaluate or yield the inner routing aliases; it merely traverses the skeleton configurations and records the exact rank (step index) at which each clique vertex updates its skeleton parent. Since the skeleton generator inherently operates in constant amortized time, this simulation run requires time proportional to the number of skeleton arborescences and should amortize to constant time. The spatial overhead requires only a simple array to store the terminal ranks. During the second pass, the algorithm compares the current step index against the pre-recorded rank to detect the final transition in constant time to calculate the exact parity of the remaining sequence to orient the endpoint control. Each layer uses the same optimization as GENSPLITARB to maintain a local routing table between and , utilizing space locally and globally. Therefore, the entire framework generates spanning arborescences for proper interval digraphs in constant amortized time, utilizing space.
5 Final remarks
The host-skeleton-routing framework introduced in this paper opens several interesting avenues for future research. A natural extension is generalizing this framework to other graph classes characterized by overlapping clique intersections. It is also worth noting that our proper interval digraph algorithm fundamentally relies on the BFS layer partition, which requires the arborescences to be rooted at the leftmost interval to guarantee the unidirectional domination property. If the desired root lies deep within the interval sequence (e.g., for ), the directed paths might need to propagate both leftward and rightward simultaneously, breaking the strict layer-by-layer structure. Whether an efficient algorithm exists for generating pivot Gray codes for spanning arborescences of proper interval digraphs rooted at an arbitrary vertex remains an open problem.
AI disclosure
We used ChatGPT and Google Gemini to assist with the implementation, debugging, and polishing of the Python code presented in the appendices. The tool materially contributed to the development and experimental validation of the sampling algorithms. The authors verified the correctness and originality of all content including references.
References
[1] M. Aigner and G. Ziegler. Cayley's formula for the number of trees, Proofs from THE BOOK, pages 173–178. Springer Berlin Heidelberg, Berlin, Heidelberg, 2004.
[2] J. Bang-Jensen and G. Gutin. Digraphs: Theory, Algorithms and Applications. Springer, London, 2nd edition, 2008.
[3] N. Behrooznia and T. Mütze. Listing spanning trees of outerplanar graphs by pivot-exchanges. In Proceedings of the 42nd International Symposium on Theoretical Aspects of Computer Science (STACS 2025), Leibniz International Proceedings in Informatics (LIPIcs). Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2025.
[4] E. Bender, B. Richmond, and N. Wormald. Almost all chordal graphs split. J. Austral. Math. Soc. Ser. A, 38(2):214–221, 1985.
[5] S. Benzer. On the topology of the genetic fine structure. Proc. Natl. Acad. Sci. U.S.A., 45(11):1607–1620, 1959.
[6] I. Berger. The enumeration of trees without duplication. IEEE Trans. Circuit Theory, 14(4):417–418, 1967.
[7] M. Bonamy, M. Hoffmann, C. Legrand-Duchesne, and G. Rote. A Gray Code for Arborescences of Tournaments. arXiv preprint, 2026.
[8] F. Bonomo, G. Durán, and M. Valencia-Pabon. Complexity of the cluster deletion problem on subclasses of chordal graphs. Theoret. Comput. Sci., 600:59–69, 2015.
[9] A. Cayley. A theorem on trees. Q. J. Math, 23:376–378, 1889.
[10] M. Chakraborty, S. Chowdhury, J. Chakraborty, R. Mehera, and R. K. Pal. Algorithms for generating all possible spanning trees of a simple undirected connected graph: an extensive review. Complex Intell. Syst., 5(3):265–281, 2019.
[11] S. Földes and P. L. Hammer. Split graphs. In Proc. 8th S.E. Conf. Combin. Graph Theory Comput., pages 311–315, 1977.
[12] H. Gabow and E. Myers. Finding all spanning trees of directed and undirected graphs. SIAM J. Comput., 7(3):280–287, 1978.
[13] F. Gavril. Algorithms for minimum coloring, maximum clique, minimum covering by cliques, and maximum independent set of a chordal graph. SIAM J. Comput., 1(2):180–187, 1972.
[14] M. Golumbic. Algorithmic Graph Theory and Perfect Graphs. Academic Press, New York, 1980.
[15] F. Gray. Pulse code communication. U.S. Patent 2,632,058, 1953.
[16] P. Hammer and B. Simeone. The splittance of a graph. Combinatorica, 1(3):275–284, 1981.
[17] T. Hill. Studies in irreversible thermodynamics IV. diagrammatic representation of steady state fluxes for unimolecular systems. J. Theor. Biol., 10(4):442–459, 1966.
[18] G. Kirchhoff. Über die auflösung der gleichungen, auf welche man bei der untersuchung der linearen verteilung galvanischer ströme geführt wird. Ann. Phys., 72:497–508, 1847.
[19] D. Knuth. The Art of Computer Programming: Combinatorial Algorithms, Part 1. Addison-Wesley Prof., 1st edition, 2011.
[20] Y. Li and J. Sawada. Gray codes for reflectable languages. Inf. Process. Lett., 109(5):296–300, 2009.
[21] B. Liu, D. Wong, C.-T. Lam, and S.-K. Im. Generating pivot Gray codes for spanning trees of complete graphs in constant amortized time. In Proceedings of the 2026 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 833–870, 2026.
[22] W. Mayeda and S. Seshu. Generation of trees without duplications. IEEE Trans. Circuit Theory, 12(2):181–185, 1965.
[23] A. Merino and T. Mütze. Traversing combinatorial 0/1-polytopes via optimization. SIAM J. Comput., 53(5):1257–1292, 2024.
[24] A. Merino, T. Mütze, and A. Williams. All your bases are belong to us: Listing all bases of a matroid by greedy exchanges. In P. Fraigniaud and Y. Uno, editors, Proc. 11th Int. Conf. Fun Algorithms (FUN), volume 226, pages 22:1–22:28, 2022.
[25] R. Merris. Split graphs. European Journal of Combinatorics, 24(4):413–430, 2003.
[26] G. Minty. A simple algorithm for listing all the trees of a graph. IEEE Trans. Circuit Theory, 12(1):120–120, 1965.
[27] T. Mütze. Combinatorial Gray codes — an updated survey. Electron. J. Comb., 30:3, 2023.
[28] T. Mütze. Notes on Pivot Gray code. Preprint, 2026.
[29] D. Naddef and W. Pulleyblank. Hamiltonicity and combinatorial polyhedra. J. Combin. Theory Ser. B, 31(3):297–312, 1981.
[30] OEIS Foundation Inc. Number of trees on n labeled nodes. Entry A000272 in The On-Line Encyclopedia of Integer Sequences, 2025.
[31] H. Prüfer. Neuer beweis eines satzes über permutationen. Arch. Mat. Phys., 27(3):142–144, 1918.
[32] F. S. Roberts. Indifference graphs. Proof techniques in graph theory, pages 139–146, 1969.
[33] D. Rose. Triangulated graphs and the elimination process. Journal of Mathematical Analysis and Applications, 32(3):597–609, 1970.
[34] F. Ruskey. Combinatorial Generation. Working version (1i) edition, 1996.
[35] C. Savage. A survey of combinatorial Gray codes. SIAM Review, (4):605–629, 1997.
[36] J. Sawada, A. Williams, and D. Wong. Inside the Binary Reflected Gray Code: Flip-Swap languages in 2-Gray code order. In T. Lecroq and S. Puzynina, editors, Combinatorics on Words, pages 172–184, Cham, 2021.
[37] J. Sawada, A. Williams, and D. Wong. Flip-swap languages in binary reflected Gray code order. Theor. Comput. Sci., 933:138–148, 2022.
[38] H. Shank. A note on hamilton circuits in tree graphs. IEEE Trans. Circuit Theory, 15(1):86, 1968.
[39] A. Shioura, A. Tamura, and T. Uno. An optimal algorithm for scanning all spanning trees of undirected graphs. SIAM J. Comput., 26(3):678–692, 1997.
[40] M. Smith. Generating spanning trees. Master's thesis, University of Victoria, 1997.
[41] V. Vajnovszki. Gray code order for Lyndon words. Discret. Math. Theor. Comput. Sci., 9(2), 2007.
[42] P. Winter. An algorithm for the enumeration of spanning trees. BIT Numer. Math., 26:44–62, 1985.
[43] D. Wood. Characterisations of intersection graphs by vertex orderings. Computing Research Repository (CoRR), 2004. arXiv:math/0408190.
Appendix A: Proofs of Lemmas related to reflectable languages
Lemma 5.1. There exists a 1-Gray code for the k-ary strings of length m excluding the all-zero string , starting from any string in which all non-zero digits are distinct, and ending at a string of the form where and for some .
Proof. When (binary case), the statement follows directly from BRGC as shown in Lemma 2.1. For , we configure each level of the reflectable recursive tree so that it begins with the desired starting digit. For every level, we then designate the leftmost and rightmost values of each local reflectable block as and , respectively. This effectively hides the digit 0 during all intermediate reflections and only exposes it at the very last block of the generation tree. This configuration guarantees that the entire sequence terminates exactly on the all-zero string . By simply dropping this final string, the sequence ends on its immediate predecessor, which differs from in exactly one position and naturally has the desired form . Figure 5.1 illustrates the structure of the first and second levels of the reflectable recursion tree when .
Lemma 5.2. There exists a 1-Gray code for the mixed radix strings of length excluding the all-zero string , starting from a legal string , and ending at a legal string of the form where , , and for some .
Proof. Such a Gray code can be constructed by modifying the standard reflectable Gray code framework of Li and Sawada [20]. We first apply a permutation to the radices, moving those with even values to the top levels of the recursive generation tree and relegating those with odd values to the bottom. Let the reordered radices be . We configure the reflectable sequence based on the parity of the available radices.
Case 1: All radices are odd. In this case, for all . We set the root level to start at 1 and end at 0. For all subsequent levels, we designate the leftmost and rightmost values of each local reflectable block as 1 and 2, respectively. This effectively hides the digit 0 during all intermediate reflections and only exposes it at the very last block of the generation tree. This configuration guarantees that the entire sequence terminates exactly on the all-zero string . By simply dropping this final string, the sequence ends on its immediate predecessor, which differs from in exactly one position and naturally has the desired form .
Case 2: At least one radix is even. Here the root level is even. We configure to start at 1 and end at 0. Since is even, the recursive tree undergoes an even number of reflections, which preserves endpoint parity. For each subsequent even-radix level, the number of strings generated at the parent level is even, so the recursive subtree again undergoes an even number of reflections, preserving endpoint parity. This allows us to safely start and end all subsequent even-radix levels on 0. When the recursion reaches the odd radices at the bottom, we apply the 0-hiding technique from Case 1. The sequence terminates at which is then dropped.
Digit at an odd-radix level: To force the sequence to start with a string in which the unique non-zero digit is located at an odd radix position, we map the target radix to the last level of the recursion tree. We configure this leaf level to start at 1 and transition to 0, while setting the

Figure 5.1: The structure of the first and second levels of the reflectable recursion tree when k = 2.
first level to start at 0 and end at 1. This forces the all-zero string to appear as the second string in the overall sequence, sandwiched between and for some . The last string then becomes . Since the predecessor and successor of differ only in this single leaf coordinate, they are adjacent in the 1-Gray code graph. Removing therefore directly connects to , achieving the desired endpoint.
Appendix B: Pivot Gray code of generated by GENARB

Appendix C: Python code to generate pivot Gray code for spanning arborescences of complete digraphs
from k_ary_linear import k_ary_linear
class Node: def init(self, val): self.val = val self.parent = None self.leaf = self # bottom leaf self.nchild = 0
def set_parent(node, parent): old = node.parent if old is not None: old.nchild -= 1 if old.nchild == 0: old.leaf = old node.parent = parent if parent is not None: parent.nchild += 1
node_list = []
def spanning_level(V, t_, n_c): if n_c == 0: yield node_list return
P = [V[i] for i in range(len(V)) if t_[i] > 0] C = [V[i] for i in range(len(V)) if t_[i] == 0] t_l = [0 for _ in range(n_c)] roots = ()
m = {P[i].val: i + 1 for i in range(len(P))} for i in range(len(C)): if C[i].parent.val in m: t_l[i] = m[C[i].parent.val] roots[i] = True
yield from spanning_level(C, t_l, len(C) - len(roots))
K = k_ary_linear(len(P), t_l) next(K) for t_l, idx in K: if t_l[idx[0]] > 0: set_parent(C[idx[0]], P[t_l[idx[0]] - 1]) if idx[0] not in roots: roots[idx[0]] = True else: del roots[idx[0]] last = next(reversed(roots)) if roots else -1 set_parent(C[idx[0]], C[last].leaf) yield from spanning_level(C, t_l, len(C) - len(roots))
for c_idx in roots: C[c_idx].parent.leaf = C[c_idx].leaf
if name == main': def str_tree(nodes): return ''.join('()->');'.format(nd.val + 1, nd.parent.val + 1 if nd.parent else -1) for nd in nodes
n = int(input('Enter n:')) prev = None for i in range(n): nd = Node(i) if prev is not None: set_parent(nd, prev) node_list.append(nd) prev = nd count = 0 for tree in spanning_level(node_list, [1] + [0] * (n - 1), n - 1): print(str_tree(tree)) count += 1 print('Total:', count)
Appendix D: Python code to generate 1-Gray code k-ary strings and mixed-radix strings
def k_ary_linear(k, alpha): n = len(alpha) d = [1 if a != 1 else -1 for a in alpha] idx = [] s = [sum(alpha)]
order = [i for i in range(n)]
if k == 1: for i in range(n): if alpha[i] == 1: order[0], order[i] = i, 0 break
def next(i, last=-1): i = order[i]
for r in range(k + 1): nl = 0 if k > 1 and r == k and last != -1 else -1
if i == n-1: if s[0] != 0: if len(idx) > 1 and idx[0] == idx[1]: idx.pop() yield alpha, idx idx[:] = []
else: i_next = order[i + 1] yield from _next(i + 1, nl) d[i_next] = 1 if alpha[i_next] == k else -d[i_next]
if r < k: a_b = alpha[i_] a_a = (alpha[i_] + d[i_] + k + 1) % (k + 1) if last != -1: if r == k-1: a_a = last elif a_a == last: a_a = (a_a + d[i_] + k + 1) % (k + 1) s[0] += a_a - a_b alpha[i_] = a_a idx.append(i_)
yield from _next(0, -1 if k == 1 else (k if alpha[order[0]] != k else k-1))
Appendix E: Python code to generate pivot Gray code for spanning arborescences of split digraphs
from k_ary_linear import k_ary_linear
class Node: def init(self, val): self.val = val self.parent = None self.leaf = self self.nchild = 0
class LinkedList: def init(self): self.map = {} self.first = -1 self.last = -1 self.len = 0
def append(self, val): assert val not in self.map self.map[val] = [self.last, -1, None] if self.last != -1: self.map[self.last][1] = val self.last = val self.len += 1 if self.first == -1: self.first = val
def remove(self, val): assert val in self.map val_last = self.map[val][0] val_next = self.map[val][1] if val_last != -1: self.map[val_last][1] = val_next if val_next != -1: self.map[val_next][0] = val_last else: self.last = val_last if self.first == val: self.first = val_next del self.map[val] self.len -= 1
def next(self, val): if val not in self.map: return -1 if self.map[val][1] != -1: return self.map[val][1] else: return self.first
def prev(self, val): if val not in self.map: return -1 if self.map[val][0] != -1: return self.map[val][0] else: return self.last
def insert_first(self, val): assert val not in self.map self.map[val] = [-1, self.first, None] if self.first != -1: self.map[self.first][0] = val self.first = val self.len += 1 if self.last == -1: self.last = val
N_K = [-1] N_I = [-1]
k_set_list = [] # k vertices list, [i] -> Node object k_cic_list = [] # cross I children list, [i][j] -> mixed radix if i is parent of j i_set_list = {} # i vertices list, [i] -> Node object i_edge = {}
host_list = {} # feasible host of i vertices, [i] -> LinkedList of feasible host k vertices host_states = {} # current host of i vertices, [i] -> current host k vertex leaf_i_vertex = [-1] # i vertex that must be a leaf when H1 -> H2
routing_list = LinkedList() # routing list of k.val, [k.val] -> [last, next, parent] routing_states = {} # current routing val of each k
root_node_ref = [None] # Node of the I-vertex acting as root root_ports = [None] # list of adjacent K-vertices of the I-root def set_parent(node, parent): old = node.parent if old is not None: old.nchild == 1 if old.nchild == 0: old.leaf = old node.parent = parent if parent is not None: parent.nchild += 1
def host(): i_keys = list(i_edge.keys())
def host_mr(i_idx): if i_idx == N_I[0]: return
i_val = i_keys[i_idx] yield from host_mr(i_idx + 1) is_first = True if host_states[i_val] == host_list[i_val].first else False # reflectable for _ in range(host_list[i_val].len - 1): leaf_i_vertex[0] = i_val yield # return next change before doing this
p_current = host_states[i_val] p_next = host_list[i_val].next(p_current) if is_first else host_list[i_val].prev(p_current) host_states[i_val] = p_next
i_set_list[i_val].parent = k_set_list[p_next]
update feasible paths
for p in i_edge[i_val]:
if p != p_current:
k_cic_list[p_current][p].remove(i_val)
if p != p_next:
k_cic_list[p_next][p].append(i_val)
update feasible routings
for k in k_set_list:
if k.parent is None or k.parent.val >= N_K[0]:
continue
if k_cic_list[k.parent.val][k.val].len >= 2:
if k.val not in routing_list.map:
routing_list.append(k.val)
routing_states[k.val] = k.parent.val
routing_list.map[k.val][2] = k.parent.val
else:
if k.val in routing_list.map:
routing_list.remove(k.val)
routing_states[k.val] = -1
yield from host_mr(i_idx + 1)
yield from host_mr(0) leaf_i_vertex[0] = -1 yield -1
def spanning_level(V, t_, n_c, last=False, first_m=None): if n_c == 0: yield return
P = [V[i] for i in range(len(V)) if t_[i] > 0] C = [V[i] for i in range(len(V)) if t_[i] == 0] t_l = [0 for _ in range(n_c)] C_ = LinkedList()
width = len(C) if first_m is None else first_m
n_str = (len(P) + 1) ** width - 1
m = {} for i in range(len(P)): m[P[i].val] = i + 1
for i in range(len(C)): if C[i].parent.val in m: t_l[i] = m[C[i].parent.val] C_.append(i)
yield from spanning_level(C, t_l, len(C) - C_.len, last and n_str == 1)
n_str -= 1 tail_holder = [0] * (len(C) - width)
K = k_ary_linear(len(P), t_l[:width]) next(K)
for ap, idx in K: t_l = ap + tail_holder this_c = C[idx[0]].val
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
skeleton update
if t_1[idx[0]] > 0: set_parent(C[idx[0]], P[t_1[idx[0]]-1]) if not idx[0] in C_.map: C_.append(idx[0]) this_p = P[t_1[idx[0]]-1].val else: C_.remove(idx[0]) set_parent(C[idx[0]], C[C_.last].leaf) this_p = C[C_.last].leaf.val
routing table update
if this_p >= N_K[0]: # parent is the I-root: the (child -> root) edge is never routable if this_c in routing_list.map: routing_list.remove(this_c) routing_states[this_c] = -1 elif k_cic_list[this_p][this_c].len == 1: if this_c in routing_list.map: routing_list.remove(this_c) routing_states[this_c] = -1 else: # when 0..011 available if ( last and n_str == 2 and k_cic_list[this_p][this_c].len >= 2 and leaf_i_vertex[0] in k_cic_list[this_p][this_c].map ): if this_c in routing_list.map: routing_list.remove(this_c) routing_list.insert_first(this_c) routing_list.map[this_c][2] = this_p routing_states[this_c] = this_p if n_c % 2 == 0 else k_cic_list[this_p][this_c].last
when 11 -> 01
elif( last and n_str == 1 and len(t_1) == 2 and leaf_i_vertex[0] in k_cic_list[this_p][this_c].map ): if this_c in routing_list.map: routing_list.remove(this_c) routing_list.insert_first(this_c) routing_list.map[this_c][2] = this_p routing_states[this_c] = leaf_i_vertex[0]
general case
else: if this_c not in routing_list.map: routing_list.append(this_c) routing_list.map[this_c][2] = this_p routing_states[this_c] = this_p
yield from spanning_level(C, t_1, len(C) - C_.len, last and n_str == 1) n_str -= 1
update leaf
for c_idx in C_.map: C[c_idx].parent.leaf = C[c_idx].leaf
def routing(): def routing_mr(i): if i == -1: yield return
mr_list = k_cic_list[routing_list.map[i][2]][i] yield from routing_mr(routing_list.map[i][1])
is_first = True if mr_list.first == routing_states[i] else False # reflectable
for _ in range(mr_list.len-1): routing_states[i] = mr_list.next(routing_states[i]) if is_first else mr_list.prev(routing_states[i]) yield from routing_mr(routing_list.map[i][1])
yield from routing_mr(routing_list.first)
def gen_split(): for H in host(): for S in spanning_level( k_set_list, [1] + [0 for _ in range(len(k_set_list) - 1)], len(k_set_list) - 1, leaf_i_vertex[0] != -1 ):
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
for R in routing(): yield
def gen_split_iroot(): root_node = root_node_ref[0] ports = root_ports[0] port_set = set(ports) V = ([root_node] + [k_set_list[p] for p in ports] + [k_set_list[j] for j in range(N_K[0]) if j not in port_set]) m = len(ports) for H in host(): for S in spanning_level( V, [1] + [0 for _ in range(N_K[0])], N_K[0], leaf_i_vertex[0] != -1, first_m=m, ): for R in routing(): yield
def initialize_split_graph(n, edges): prev = None for v in range(n): new_node = Node(v) if prev is not None: set_parent(new_node, prev) k_set_list.append(new_node) k_cic_list.append([LinkedList() for _ in range(n)]) for cic in k_cic_list[-1]: cic.append(v) prev = new_node
for i_val, i_parents in edges.items(): assert i_val not in i_set_list assert len(i_parents) > 0 assert len(set(i_parents)) == len(i_parents) assert all(0 <= p < n for p in i_parents)
i_edge[i_val] = list(i_parents)
new_node = Node(i_val) i_set_list[i_val] = new_node new_node.parent = k_set_list[i_parents[0]]
i_ll = LinkedList() for p in i_parents: i_ll.append(p) host_list[i_val] = i_ll host_states[i_val] = i_parents[0]
for p in i_parents[1]: k_cic_list[i_parents[0]][p].append(i_val)
N_K[0] = n N_I[0] = len(i_edge)
for k in k_set_list[1]: if k_cic_list[k.parent.val][k.val].len > 1: routing_list.append(k.val) routing_list.map[k.val][2] = k.parent.val routing_states[k.val] = k.parent.val
def initialize_split_graph_iroot(n, edges, root): assert root in edges assert len(edges[root]) > 0 assert len(set(edges[root])) == len(edges[root]) assert all(0 <= p < n for p in edges[root])
ports = list(edges[root]) port_set = set(ports)
for v in range(n): new_node = Node(v) k_set_list.append(new_node) k_cic_list.append([LinkedList() for _ in range(n)]) for cic in k_cic_list[-1]: cic.append(v)
the I-root
root_node = Node(root)
root_node_ref[0] = root_node
root_ports[0] = ports
C_order = [k_set_list[p] for p in ports] + [k_set_list[j] for j in range(n) if j not in port_set] set_parent(C_order[0], root_node) for i in range(1, len(C_order)):
357 set_parent(C_order[i], C_order[i - 1]) 358 359 for i_val, i_parents in edges.items(): 360 if i_val == root: 361 continue 362 assert i_val not in i_set_list 363 assert len(i_parents) > 0 364 assert len(set(i_parents)) == len(i_parents) 365 assert all(0 <= p < n for p in i_parents) 366 367 i_edge[i_val] = list(i_parents) 368 369 new_node = Node(i_val) 370 i_set_list[i_val] = new_node 371 new_node.parent = k_set_list[i_parents[0]] 372 373 i_ll = LinkedList() 374 for p in i_parents: 375 i_ll.append(p) 376 host_list[i_val] = i_ll 377 host_states[i_val] = i_parents[0] 378 379 for p in i_parents[1:]: 380 k_cic_list[i_parents[0]][p].append(i_val) 381 382 N_K[0] = n 383 N_I[0] = len(i_edge) # excludes the root 384 385 # initial routable clique edges 386 for k in k_set_list: 387 if k.parent is None or k.parent.val >= n: 388 continue 389 if k_cic_list[k.parent.val][k.val].len > 1: 390 routing_list.append(k.val) 391 routing_list.map[k.val][2] = k.parent.val 392 routing_states[k.val] = k.parent.val 393 394 def decode_tree(): 395 396 tree = { 397 k.val: (-1 if k.parent is None else k.parent.val) 398 for k in k_set_list 399 } 400 tree.update({i.val: i.parent.val for i in i_set_list.values()}) 401 if root_node_ref[0] is not None: 402 tree[root_node_ref[0].val] = -1 403 404 for c, parent in routing_states.items(): 405 if parent != -1: 406 tree[c] = parent 407 408 return tree 409 410 def str_hsr_tree(): 411 tree = decode_tree() 412 return ’’.join( 413 ’{}->{}; ’.format(v, tree[v] if tree[v] != -1 else -1) 414 for v in sorted(tree) 415 ) 416 417 418 if name == ’main’: 419 initialize_split_graph_iroot(4, {4: [0, 1, 2], 5: [1, 3]}, root=4) 420 421 print(’==============================================’) 422 cnt = 0 423 for _ in gen_split_iroot(): 424 print(str_hsr_tree()) 425 cnt += 1 426 print(’Total: ’ + str(cnt)) 427 428 # initialize_split_graph(4, {4: [0, 1, 2], 5: [1, 3]}) 429 # print(’==============================================’) 430 # cnt = 0 431 # for _ in gen_split(): 432 # print(str_hsr_tree()) 433 # cnt += 1 434 # print(’Total: ’ + str(cnt)) 39