This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

String representation of trivalent 2-stratifolds with trivial fundamental group

Myriam Hernández-Ketchul           Jesús Rodríguez-Viorato
(June 22nd, 2020)
Abstract

We give a Python program that is capable to compute and print all the distinct trivalent 2-stratifold graphs up to NN white vertices with trivial fundamental group (see [6]). Our algorithm uses the three basic operations described in [7] to construct new graphs from any set of given graphs. We iterate this process to construct all the desired graphs. The algorithm includes an optimization that reduces the repetition of generated graphs, this is done by recognizing equivalent white vertices of a graph under automorphism. We use a variation of the AHU algorithm to identify those vertices and as well to distinguish isomorphic graphs in linear time. The returned string from the AHU algorithm is also used as a hashing function to search for repeated graphs in amortized constant time.

1 Introduction

Since 2016, the authors José Carlos Gómez-Larrañaga, Francisco González-Acuña, and Wolfgang Heil have studied 2-stratifolds [5]. There are multiple motivations to follow their work, but one of the most interesting is the applications of the 2-stratifolds on the field of Topological Data Analysis.

The classification of 2-manifolds has been well studied, but the study of the 2-stratifolds has just started. On [7], Gómez-Larrañaga, González-Acuña, and Wolfgang started to analyze the ones with trivial fundamental group, giving a process to build them. And continuing with that work, it’s easy to ask how many of those exist.

Moreover, using the operations described in their work, we started to wonder if there was possible to use them to get every 2-stratifold. Yair Hernández, wrote a computational algorithm [8] to build some of them, and based on that code, we decided to extend it to get the 2-stratifolds meticulously; in an optimized way.

Since the operations described on [7] are performed on white vertices, it was decided to use the number of white vertices as a parameter for the algorithm, limiting the number of graphs that it was going to build. Therefore our program can calculate and draw the graph representation defined in [7] of every 2-stratifold with trivial fundamental group up to NN white vertices.

The code was written on Python and can be consulted on [1]. In order to identify different graphs, it used a modified version of the AHU algorithm. And to optimize the algorithm, there is defined an identification among white vertices under automorphisms of the graph (see def. 5.3). The modified version of the AHU algorithm, the algorithm 4, allows us to identify every graph with a unique string, which is the string representation, that is used as a hash to discard the repeated graphs and optimize the building process.

The contents of this paper include a description of the algorithm previously mentioned and the proof that it actually builds all the graphs that it is asked to. In section 2, there are given basic graph theory definitions, that are necessary to understand the proves. In section 3, there are proven some known results of graph isomorphisms but applied to the graph representations of the 2-stratifolds. In the next section,“Characterizing weighted trees with a string”, we describe the modified version of the AHU algorithm and we explain how it is helpful to solve the problem of classifying the trivalent graphs and therefore the 2-stratifolds with trivial fundamental group. In the section “The graph generator algorithm”, we describe the main algorithm that assigns a string representation to every graph, and we give the results of the construction of the graphs up to 11 white vertices, including a comparison between the optimized and non-optimized version. Finally, in “Nomenclature” we explained the tag that is given to every graph at the end of the algorithm because although the string representation is unique, it doesn’t work as a quick resume of the general shape of the graph.

2 Preamble

Definition 2.1.

We will say that a graph generated by a simply-connected trivalent 2-dimensional stratifold is a trivalent graph.

Definition 2.2.

Let be GG a graph, a set of vertices {v0,v1,,vn}G\{v_{0},v_{1},...,v_{n}\}\subset G such that viv_{i} is adjacent to vi+1v_{i+1}, and vivjv_{i}\neq v_{j} for every 0i,jn10\leq i,j\leq n-1 is called a path from v0v_{0} to vnv_{n} in GG.

Definition 2.3.

The degree of a vertex vv in a graph GG is the number of vertices in GG that are adjacent to vv. The set of all the vertices that are adjacent to vv are the neighbors of vv and we denote them by N(v)N(v). A vertex of degree 1 is a leaf.

Definition 2.4.

Given a uvu-v path RR in GG the length of the path is the sum of the weights of the edges encountered in RR. For two vertices uu and vv, the shortest path is the uvu-v path with minimum length, and the largest path is the uvu-v path with maximum length. The length (without weights) of a path is the length of the path considering that all the weights are 1.

Definition 2.5.

Let vv be a vertex of a graph GG, its eccentricity e(v)e(v) is the length (without weights) of the largest path from vv to another vertex in GG. The radius of GG, rad(G)rad(G), is the smallest eccentricity among the vertices of GG. For any vertex vv, such that e(v)=rad(G)e(v)=rad(G) we say that vv is a central vertex of GG, if GG has only one central vertex uu, we say that uu is the center of GG.

Definition 2.6.

Given a graph GG, we say that GG is a tree if and only if for every v,wv,w vertices of GG, there exists a path from vv to ww and there is no path with positive length from vv to itself. A rooted tree is a tree with a special vertex identified as the root.

Definition 2.7.

On a rooted tree, a vertex vv is a child of vertex ww if, in the path from the root to vv, vv immediately succeeds ww. We said that ww is parent of vv if and only if vv is child of ww.

3 Isomorphic graphs

Definition 3.1.

Two weighted graphs GG and HH are isomorphic if there exists a bijective function ϕ:V(G)V(H)\phi:V(G)\to V(H) such that two vertices uu and vv are adjacent in GG if and only if ϕ(u)\phi(u) and ϕ(v)\phi(v) are adjacent in HH, and for every edge, uvu-v in GG, the edge ϕ(u)ϕ(v)\phi(u)-\phi(v) in HH has the same weight as uvu-v. If there is no such function ϕ\phi as described above, the GG and HH are non-isomorphic graphs. (Definition from [4]) Moreover, for GG and HH rooted trees with roots rG,rHr_{G},r_{H}, respectively, we say that GG and HH are isomorphic as rooted trees if they are isomorphic and ϕ(rG)=rH\phi(r_{G})=r_{H}.

Lemma 3.1.

If two graphs GG and HH are isomorphic with a function ϕ:V(G)V(H)\phi:V(G)\to V(H), for uu vertex of GG, uu is a leaf of GG if and only if ϕ(u)\phi(u) is a leaf of HH.

Proof.

Let uu a leaf of GG, then by definition, there exists only one vertex adjacent to uu in GG, suppose vv. As uu and vv are adjacent in GG, ϕ(u)\phi(u) and ϕ(v)\phi(v) are adjacent in HH. For any other ww vertex in GG, different from uu or vv; ww is not adjacent to uu in GG and therefore ϕ(w)\phi(w) is not adjacent to ϕ(u)\phi(u) in HH. Then, ϕ(v)\phi(v) is the only vertex adjacent to ϕ(u)\phi(u) in HH, concluding that ϕ(u)\phi(u) must be a leaf of HH. Analogously if ϕ(u)\phi(u) is a leaf of HH we can conclude that uu must be a leaf of GG. ∎

Corollary 3.1.1.

If two graphs GG and HH are isomorphic, then they have the same number of leaves.

Definition 3.2.

Two trivalent graphs GG and HH are isomorphic as trivalent graphs if there is an isomorphism ϕ\phi as weighted graphs such that, if B(G),B(H)B(G),B(H) are the sets of black vertices of G,HG,H, and W(G),W(H)W(G),W(H) are the sets of white vertices of G,HG,H, the functions ϕB(G):B(G)B(H)\phi\restriction_{B(G)}:B(G)\to B(H) and ϕW(G):W(G)W(H)\phi\restriction_{W(G)}:W(G)\to W(H) are bijective.

Lemma 3.2.

If two trivalent graphs GG and HH are isomorphic, then they have the same number of white and black vertices and the same number of leaves.

Proof.

If GG and HH are two trivalent graphs that are isomorphic, there exists ϕ:V(G)V(H)\phi:V(G)\to V(H) such that ϕB(G):B(G)B(H)\phi\restriction_{B(G)}:B(G)\to B(H) and ϕW(G):W(G)W(H)\phi\restriction_{W(G)}:W(G)\to W(H) are bijective, therefore |B(G)|=|B(H)||B(G)|=|B(H)| and |W(G)|=|W(H)||W(G)|=|W(H)|. And by corollary 3.1.1, GG and HH have the same number of leaves. ∎

Theorem 3.3 (Theorem 2.7 in [4]).

There exists a unique path between any two vertices of a tree.

Lemma 3.4.

For GG and HH two isomorphic trees with isomorphism function ϕ\phi, for every two vertices uu, vv in GG, the length of the uvu-v path in GG is the same as the length of the ϕ(u)ϕ(v)\phi(u)-\phi(v) path in HH.

Proof.

Given that GG and HH are trees, by theorem 3.3 there exists a unique path between any two vertices in them. Let uu, vv be vertices in GG, there exists R={u=r0,r1,,rn1,v=rn}R=\{u=r_{0},r_{1},...,r_{n-1},v=r_{n}\} a unique path between them, such that RR is a sequence of adjacent vertices without repetition in GG. For two adjacent vertices a,ba,b let’s denote (a,b)(a,b) as the length of the edge between them, then the length of RR is

length(R)=i=0n1(ri,ri+1)length(R)=\sum_{i=0}^{n-1}(r_{i},r_{i+1})

First, notice that by the definition of path rir_{i} and ri+1r_{i+1} are adjacent in GG, then ϕ(ri),ϕ(ri+1)\phi(r_{i}),\phi(r_{i+1}) are adjacent in HH, for every ii, 0in10\leq i\leq n-1. Also by definition of RR, rirjr_{i}\neq r_{j} for iji\neq j, and by definition of ϕ\phi this implies that ϕ(ri)ϕ(rj)\phi(r_{i})\neq\phi(r_{j}) for iji\neq j.
Then Q={ϕ(u)=ϕ(r0),ϕ(r1),,ϕ(rn1),ϕ(v)=ϕ(rn)}Q=\{\phi(u)=\phi(r_{0}),\phi(r_{1}),...,\phi(r_{n-1}),\phi(v)=\phi(r_{n})\} is a sequence of adjacent vertices without repetition in HH, which implies that QQ is a ϕ(u)ϕ(v)\phi(u)-\phi(v) path, and since HH is a tree, QQ is the unique ϕ(u)ϕ(v)\phi(u)-\phi(v) path in HH.
Finally, by definition of ϕ\phi for every edge, aba-b in GG, the edge ϕ(a)ϕ(b)\phi(a)-\phi(b) in HH has the same weight, therefore:

length(Q)=i=0n1(ϕ(ri),ϕ(ri+1))=i=0n1(ri,ri+1)=length(R)length(Q)=\sum_{i=0}^{n-1}(\phi(r_{i}),\phi(r_{i+1}))=\sum_{i=0}^{n-1}(r_{i},r_{i+1})=length(R)

Corollary 3.4.1.

For GG and HH two isomorphic trees, their radius will have the same length.

Lemma 3.5.

Let GG and HH be two isomorphic trees with isomorphism function ϕ\phi, for any vv vertex of GG, the function ϕN(v)\phi\mid_{N(v)}, where N(v)N(v) is the set of the neighbors of vv, is a bijective function with codomain N(ϕ(v))N(\phi(v)) in HH.

Proof.

Given vv a vertex of GG, let xN(v)x\in N(v). That happens if and only if length1(v,x)=1length_{1}(v,x)=1. In the other hand, ϕ(x)\phi(x) is neighbor of ϕ(v)\phi(v) if and only if length1(ϕ(v),ϕ(x))=1length_{1}(\phi(v),\phi(x))=1. By using a particular case of the previous lemma we have that length1(v,x)=length1(ϕ(v),ϕ(x))length_{1}(v,x)=length_{1}(\phi(v),\phi(x)), therefore xN(v)x\in N(v) if and only if ϕ(x)N(ϕ(v))\phi(x)\in N(\phi(v)). Since ϕ\phi is a bijection then ϕN(v):N(v)N(ϕ(v))\phi\mid_{N(v)}:N(v)\to N(\phi(v)) is a bijection too. This means that the images of the neighbors of vv are the neighbors of the image of vv. ∎

Let’s denote (a,b)p(a,b)_{p} as the path from aa to bb in the graph and length1(a,b)length_{1}(a,b) as its length (without weights), since all the graphs generated by the simply-connected trivalent 2-dimensional stratifolds are trees, by Theorem 3.3 this is well defined.

Lemma 3.6.

For any vertex vv in a tree GG, if uu is a vertex such that length1(u,v)=e(v)length_{1}(u,v)=e(v) then uu is a leaf.

Proof.

Suppose that uu is not a leaf, then the degree of uu is at least 22, then there exists xx neighbor of uu such that x(v,u)px\not\in(v,u)_{p}. By theorem 3.3 we know that such xx exists, because there is a unique path from vv to uu which means that there is only one neighbor of uu connected to vv. If there where x,yx,y neighbors of uu connected to vv, there would be two paths from vv to uu and that is a contradiction.
Let’s notice that the

e(v)=length1(v,u)<length1(v,u)+1=length1(v,u)+length1(u,x)=length1(v,x),e(v)=length_{1}(v,u)<length_{1}(v,u)+1=length_{1}(v,u)+length_{1}(u,x)=length_{1}(v,x),

but that’s a contradiction to the definition of eccentricity. Therefore the degree of uu must be at most 1, and uu is a leaf of GG. ∎

Theorem 3.7 (Uniqueness of the center).

Let GG be a trivalent graph, then there exists cc center of GG and it is unique.

Proof.

By definition, there exists at least one vertex vv such that e(v)=rad(G)e(v)=rad(G).
First, let’s notice that two vertices of different colors in a trivalent graph can’t be both central vertices. Every trivalent graph has the property that all the neighbors of a white vertex are black vertices and vice versa, also all the leaves are white. Then by parity, the length1length_{1} from any white vertex to a leaf would be even and the length1length_{1} from any black vertex to a leaf would be odd, using the lemma 3.6 we can conclude that the eccentricity of a white vertex would be always different from the eccentricity of a black vertex, which means that they can’t be both central vertices.
Now suppose that there exists uvu\neq v such that uu is a central vertex of GG. Without loss of generality we can assume that u,vu,v are both white. Then there exists xx a black vertex such that x(u,v)px\in(u,v)_{p}. We would prove that e(x)<e(v)e(x)<e(v).
Let l1,l2,.,lnl_{1},l_{2},....,l_{n} be the leaves of GG, by definition, for any leaf liGl_{i}\in G, we will have length1(v,li)e(v)length_{1}(v,l_{i})\leq e(v) and length1(u,li)e(u)length_{1}(u,l_{i})\leq e(u).
Notice that for any lil_{i} we have two options, x(v,li)px\not\in(v,l_{i})_{p} or x(v,li)px\in(v,l_{i})_{p}. We will analyze both cases.
Case 1, x(v,li)px\not\in(v,l_{i})_{p}:
If x(v,li)px\not\in(v,l_{i})_{p}, in particular (x,u)p(v,li)p(x,u)_{p}\not\subset(v,l_{i})_{p} because x(x,u)p(v,u)px\in(x,u)_{p}\subset(v,u)_{p} and the last one is unique, by lemma 3.3. Notice that there exists a unique vertex w(v,x)pw\in(v,x)_{p} (it could happen that w=vw=v) such that (v,li)p=(v,w)p(w,li)p(v,l_{i})_{p}=(v,w)_{p}\cup(w,l_{i})_{p} and (w,li)p(v,x)p={w}(w,l_{i})_{p}\cap(v,x)_{p}=\{w\}, therefore we have that

length1(w,li)+length1(x,w)=length1(x,li)<length1(x,li)+length1(u,x)=length1(u,li)e(u)=e(v)length_{1}(w,l_{i})+length_{1}(x,w)=length_{1}(x,l_{i})<length_{1}(x,l_{i})+length_{1}(u,x)=length_{1}(u,l_{i})\leq e(u)=e(v)

Then length1(x,li)<e(v)length_{1}(x,l_{i})<e(v).
Case 2, x(v,li)px\in(v,l_{i})_{p}:
Since x(v,li)px\in(v,l_{i})_{p} then (v,li)p=(v,x)p(x,li)p(v,l_{i})_{p}=(v,x)_{p}\cup(x,l_{i})_{p} therefore

length1(x,li)<length1(x,li)+length1(v,x)=length1(v,li)e(v)length_{1}(x,l_{i})<length_{1}(x,l_{i})+length_{1}(v,x)=length_{1}(v,l_{i})\leq e(v)

which implies length1(x,li)<e(v)length_{1}(x,l_{i})<e(v).
From both cases, we can conclude that length1(x,li)<e(v)length_{1}(x,l_{i})<e(v) for any leaf liGl_{i}\in G, then

e(x)=max1inlength1(x,li)<e(v),\displaystyle e(x)=\max_{1\leq i\leq n}length_{1}(x,l_{i})<e(v),

contradicting the fact that vv and uu were both central vertices because there is another vertex with lower eccentricity than the radius.
This proves that for any trivalent graph, the center exists and it is unique. ∎

Lemma 3.8.

Any two trivalent graphs are isomorphic as trivalent graphs if and only if they are isomorphic as graphs.

Proof.

By definition, it is clear that isomorphism as trivalent graphs implies isomorphism. We only need to prove that isomorphism implies isomorphism as trivalent graphs, which is the isomorphism function determines a bijection between the set of black vertices of both graphs, analogously with the white vertices.
Let GG and HH be two trivalent graphs. If instead of the length in lemma 3.4 we consider the length (without weights) we can conclude that for any vertex vGv\in G, if ϕ(v)=wH\phi(v)=w\in H then e(v)=e(w)e(v)=e(w).
Using the same parity argument as in the previous proof, notice that e(v)=e(w)e(v)=e(w) if only if v,wv,w are both white or both black. Moreover, e(v),e(w)e(v),e(w) would be odd if and only if vv and ww are black, and would be even if and only if vv and ww are white.
This gives us a partition of the graph that assures us that the image of any white vertex is going to be a white vertex, and the image of any black vertex is going to be a black vertex. Therefore the restriction of ϕ\phi to the set of black vertices in GG is a bijection with codomain the set of black vertices in HH, analogously with the white vertices. Then we can conclude that isomorphism implies isomorphism as trivalent graphs. ∎

Lemma 3.9.

For GG and HH two isomorphic trivalent graphs with isomorphism function ϕ\phi, then the center of HH is the image of the center of GG under ϕ\phi.

Proof.

As a result of the lemma 3.4, if we consider the length (without weights) instead of the length, for any vGv\in G, the eccentricity of vv in GG will be the same as the eccentricity of ϕ(v)\phi(v) in HH. Let cc be the center of GG, which is unique, using corollary 3.4.1 we have that

rad(H)=rad(G)=e(v)=e(ϕ(c))rad(H)=rad(G)=e(v)=e(\phi(c))

By definition, since rad(H)=e(ϕ(c))rad(H)=e(\phi(c)) we can conclude that ϕ(c)\phi(c) is the center of HH. ∎

Lemma 3.10.

Given GG and HH trivalent graphs, if we select the center of each graph as its root, GG and HH are isomorphic as trivalent graphs if and only if GG and HH are isomorphic as rooted trees.

Proof.

If GG and HH are isomorphic as trivalent graphs, by lemma 3.9, since the center of HH is the image of GG under the isomorphism function, it is immediate that GG and HH are isomorphic as rooted trees. Now let’s suppose that GG and HH are isomorphic as rooted trees. By definition, the isomorphism as rooted trees implies that GG and HH are isomorphic, therefore by lemma 3.10, since GG and HH are two trivalent graphs that are isomorphic, then they are isomorphic as trivalent graphs. ∎

4 Characterizing weighted trees with a string

So far, we have described how two isomorphic trivalent graphs behave, but we need tools to identify if two trivalent graphs are isomorphic. This is important because the main goal is to know how many and which are all the trivalent stratifolds for a given number of white vertices. Since the trivalent stratifolds are associated with a unique trivalent graph, having a classification for the trivalent graphs gives us a classification for the trivalent stratifolds.

The generation of all the trivalent graphs is an iterative process that creates a lot of isomorphic graphs, we will discuss this process further in Section 6. But it is because of this excess of repetitions, that we need an optimal algorithm that can recognize isomorphic graphs with as few operations as possible.

In the book The Design and Analysis of Computer Algorithms [2] the authors propose an algorithm that allows us to identify if two non-weighted rooted trees are isomorphic in O(n)O(n) time. This algorithm is known as the AHU algorithm, the acronyms AHU comes from the initials of the authors Aho, Hopcroft, and Ullman. To use this algorithm is necessary to remark that two isomorphic trees could be non-isomorphic as rooted trees (see Fig. 1 for an example).

Refer to caption
Figure 1: This is an example of two isomorphic trees that aren’t isomorphic as rooted trees. On each tree, we have marked in bold black the root.

In the article Tree isomorphism Algorithms: Speed vs. Clarity [3], there is an algorithm that improves the idea of Aho, Hopcroft, and Ullman, by implementing the use of parenthetical tuples. And then substituting the use of ‘(’, ‘)’ for ‘1’ and ‘0’ respectively, the latest have a natural order.

Given a rooted tree TT, the main idea of the algorithm is to assign a unique string to each vertex of TT recursively. The string assigned to a vertex is created recursively from the string associated with its children. And finally, assign to TT the string associated with its root. Then we can conclude that two rooted trees are isomorphic if and only if they have the same associated string.

We now present the pseudo-code of the AHU Algorithm. An example of this process can be seen in Fig. 2.

Algorithm 1 AHU(vv: vertex)
  if vv is childless then
     Give vv the tuple name “10”
     return  “10”
  else
     Set L=L=\emptyset
     for all ww child of vv do
        tagtag = AHU(ww);
        Append tagtag to LL
     end for
     Sort LL using binary order
     Set temp=temp= Concatenation of tags in LL
     Give vv the tuple name “1temp01temp0
  end if
Refer to caption
Figure 2: Example of labels given by running the AHU to a rooted tree

Although this algorithm allows us to recognize if two rooted trees are isomorphic, it doesn’t allow us to distinguish if two rooted trees with weights are isomorphic, because it doesn’t take into account the weights. Since trivalent graphs are weighted trees, this algorithm doesn’t work for our problem in the first instance.

By theorem 3.7, given a trivalent graph GG, there is a unique vertex vv such that vv is the central vertex of GG, we call vv the center of GG. The uniqueness of the center for every trivalent graph allows us to mark this vertex as the root of the trivalent graph, without ambiguity.

We have proven that the center exists, but so far we only have given an exhaustive algorithm to find it. In [2] on pages 176 to 179, Aho, Hopcroft, and Ullman describe the algorithm Depth-first search whose purpose is to find the largest path in a tree. It is proven that this algorithm only needs O(max{n,e})O(\max\{n,e\}) steps on a graph with nn vertices and ee edges. The idea of this algorithm is to visit every vertex of the tree in an ordered way, going deeper before continuing to another branch of the tree, this way we can assure that we visit every vertex exactly once.

Algorithm 2 Depth-first_search(vv:vertex)
  if vv is childless then
     return  v{v}
  else
     Set length=0length=0 and longestPath=longestPath=\emptyset
     for all ww child of vv do
        Set path=path=Depth-first_search(ww) and LL as the length of pathpath.
        if L>lengthL>length  then
           Set length=Llength=L and longestPath=pathlongestPath=path
        end if
     end for
     return  vlongestPath{v}\cup longestPath
  end if

To find the center of the trivalent graph it is only necessary to find the longest path in the tree and then find the middle vertex of it. This will always be the center of the tree. The pseudo-code is the algorithm 3.

The Algorithm 3 successfully finds the center of any trivalent graph because it first finds a path of maximal length (a diameter) of the tree. Any diameter of a trivalent has an even length (see Theorem 3.7 ). By the definition of the center, all vertices must be at a distance at most half of the diameter. That is why the center must be in the middle of any diameter.

Algorithm 3 center(GG: Trivalent graph)
  Set vv a vertex of GG
  Set longestPath=longestPath=Depth-first_search(vv)
  Set ww as the last vertex of the path longestPathlongestPath.
  Set longestPath=longestPath=Depth-first_search(ww)
  Set centercenter as the middle vertex of longestPathlongestPath
  return centercenter

To prove that we can find a diameter with two runs of DFS we do as follows. What we have to show is that at the first run of the DFS we end up at the end of a diameter of GG. So, at the next run, we will end up at the other end of the diameter. Then, what we have to show is that that farthest vertex ww from a given vertex vv in GG belongs to a diameter of GG.

Let ww be one of the farthest vertices from vv. Observe first that ww has to be a leaf, otherwise, we can find a farther vertex from vv. Now, let γ\gamma a diametrical path of GG. As ww is a leaf, if ww belongs to γ\gamma then the proof would be over. Lets call aa and bb the ends of γ\gamma. By the definition of ww, the vertices aa and bb need to be no further from vv than ww. If one of them were closer to vv, we can prove that one of the paths from ww to aa or bb is longer than γ\gamma (an analysis by cases is needed it here). This contradicts the fact that γ\gamma is a diameter. Similarly, if both aa and bb are as far from vv than ww, it implies that one of the paths from ww to aa or bb is as long as γ\gamma, making ww the end of a diameter. Which completes the proof. So, the second time that the DFS runs, it will find the other end of the diameter.

This algorithm needs twice the number of steps that Deep-first_search plus a constant, which means that this algorithm is still linear and only depends on the number of vertices and edges of the graph.

Now, every trivalent graph can be seen as a rooted tree and therefore we can apply the AHU algorithm to it. The problem is that the AHU algorithm doesn’t take into account the weights of the edges, but we have solved this problem by instead of assigning only numbers ‘1’ and ‘0’ we include the numbers ‘2’ and ‘3’ depending on the weight in the edge that connects the vertex with its father. This algorithm still runs on linear time.

The recursive part of the algorithm is given by the following pseudo-code:

Algorithm 4 AHU-modified(vv:vertex)
  if vv is childless then
     if vv has no father or Weight[v,father(v)]=1Weight[v,father(v)]=1  then
        Give vv the tuple name “01”;
     else
        Give vv the tuple name “23”;
     end if
     return  The tuple name of vv
  else
     Set L=L=\emptyset
     for all ww child of vv do
        tagtag = AHU-modified(ww);
        Append tagtag to LL
     end for
     Sort LL using base four order
     Set temp=temp= Concatenation of tags in LL
     if vv has no father or Weight[v,father(v)]=1Weight[v,father(v)]=1  then
        Give vv the tuple name “0temp10temp1”;
     else
        Give vv the tuple name “2temp32temp3”;
     end if
     return  The tuple name of vv
  end if

Now, given any trivalent graph, to get its string it is necessary to get its center first and then get the string associated with that vertex. For the complete implementation, see Algorithm 5.

Algorithm 5 TG_to_string(GG: Trivalent graph)
  Set cc as the output of center(GG);
  Set cc as the root of GG.
  Vertex_to_string(cc);
  Return the tuple name of cc;
Definition 4.1.

Given a trivalent graph GG we call the output of TG_to_string (GG) [5] as the string representation of GG.

Theorem 4.1.

Given two trivalent graphs, they are isomorphic if and only if they have the same string representation.

To prove this theorem, we are going to give an algorithm that recovers the original graph given a string, and this will prove that there is a unique graph associated with any string.

Algorithm 6 String_to_TG(SS: string, fatherfather: vertex)
  if fatherfather is NONE then
     Draw a vertex vv;
     State fatherfather as vv;
  end if
  if The first element of SS is 0 then
     Set CloseClose as 1;
  else
     Set CloseClose as 3;
  end if
  Set ii as 2
  while The ii-th element of SS is different from CloseClose do
     if The ii-th element of SS is 0 then
        Draw a vertex ww connected to fatherfather with weight 1;
     else
        Draw a vertex ww connected to fatherfather with weight 2;
     end if
     Set PP as the string SS without its first element;
     Set ii = String_to_TG(PP, ww) + 2;
  end while
  Return ii;

This algorithm draws a unique trivalent graph given a string representation, therefore we are giving a bijection between the trivalent graphs and the string representations, proving the theorem 4.1.

This algorithm can be extended for n-colored trees in general, also it can be extended for trees with a greater amount of weights, it only needed to add more start-close indicator numbers to identify the different weights.

5 The graph generator algorithm

Given a tivalent graph, one can generate more by applying the operations O1 or O2 to any white vertex of it. Or given two trivalent graphs, we can generate a new one by applying the operation O1* in one white vertex of each graph. It is proven in [7] that all the trivalent graphs can be obtained by recursively using these operations in all the previous trivalent graphs, starting with the B111 and B12 trees.

The B111 and B12 trees are defined in [7] in Definition 1.

Definition 5.1.
  1. 1.

    The B111-tree is the bi-colored tree consisting of one black vertex incident to three edges each of label 1 and three terminal white vertices each of genus 0.

  2. 2.

    The B12-tree is the bi-colored tree consisting of one black vertex incident to two edges one of label 1, the other of label 2, and two terminal white vertices each of genus 0.

Also the operations O1, O2 and O1* are defined in [7].

Definition 5.2.

In a trivalent graph Γ\Gamma let ww be a white vertex and let e1,,eme_{1},...,e_{m} be the edges incident to ww (m0m\geq 0) and let bib_{i} be the black vertex incident to eie_{i}(i=1,,mi=1,...,m). We define the operations O1O1 and O2O2 on Γ\Gamma that changes Γ\Gamma to a new trivalent graph Γ1\Gamma_{1} as follows:

  1. 1.

    O1. Let 0km0\leq k\leq m. Attach one white vertex of a B111-tree to ww, cut off bk1,,bmb_{k-1},...,b_{m} from ww and attach bk+1,,bmb_{k+1},...,b_{m} to another white vertex of the B111-tree.

  2. 2.

    O2. Attach a B12-tree to ww so that the terminal edge has label 1.

  3. 3.

    O1*. On the other hand, let Γ1\Gamma_{1} and Γ2\Gamma_{2} be two disjoint trivalent graphs and let wiw_{i} be a white vertex of Γi\Gamma_{i} (i=1,2i=1,2). Attach a B111-tree to Γ1Γ2\Gamma_{1}\cup\Gamma_{2} so that w1w_{1} and w2w_{2} are identified with two distinct white vertices of the B111-tree.

To get all the trivalent graphs with nn white vertices, we have implemented a program that has two fundamental parts. The first part constructs all the trivalent graphs with ii white vertices (2in2\leq i\leq n) and the second part reduces the list by eliminating the repetitions.

Algorithm 7 Construct_TG(mm:integer)
  Create Complete_listComplete\_list a list with m1m-1 empty lists;
  Set the B12-tree as the first element of Complete_list[0]Complete\_list[0];
  Set the B111-tree as the first element of Complete_list[1]Complete\_list[1];
  for all ww white vertex of B12-tree do
     Set Γ\Gamma as the rif the graph is already there. Here is when we have to use the Characterizing string from ing O2 to ww;
     Add Γ\Gamma to Complete_list[1]Complete\_list[1];
  end for
  for nn in [4,n][4,n] do
     for all qq graph in Complete_list[n3]Complete\_list[n-3] do
        for all ww white vertex of gg do
           Set Γ\Gamma as the result of applying O2 to gg in the vertex ww.
           Add Γ\Gamma to Complete_list[n1]Complete\_list[n-1] if it not already there.
        end for
     end for
     for all gg graph in Complete_list[n4]Complete\_list[n-4] do
        for all ww white vertex of gg do
           Set Γ\Gamma as the result of applying O1 to gg in the vertex ww.
           Add Γ\Gamma to Complete_list[n1]Complete\_list[n-1] if it not already there.
        end for
     end for
     for ii in [0,n1][0,n-1] do
        if ni50n-i-5\geq 0 then
           for all pair (u,v)(u,v) where uu is a white vertex of a graph in Complete_list[i]Complete\_list[i], vv is a white vertex of a graph in Complete_list[ni5]Complete\_list[n-i-5] do
              Set Γ\Gamma as the output of applying O1O1^{*} using the vertices u,vu,v;
              Add Γ\Gamma to Complete_list[n1]Complete\_list[n-1] if it not already there.
           end for
        end if
     end for
  end for

We should mention that whenever we add a graph to Complete_list[n1]Complete\_list[n-1] we have to check if the graph is already there. Here is when we have to use the string representation of its elements (see Def. 4.1) to compare them. Even more, we can set the string representation as a hashing function, so we don’t have to iterate over all the elements of Complete_list[n1]Complete\_list[n-1] to decide if it already there or not, and decide it in amortized constant time. The complete implementation can be found in the repository https://github.com/MyHerket/TrivalentStratifold in GitHub.

As explained before, the creation of a new trivalent graph is an iterative process. And we are going to prove that the previous algorithm creates all the trivalent graphs with nn white vertices.

Lemma 5.1.

Let GG be a trivalent graph, there exists at least one leaf ww of GG such that the weight of the adjacent edge to ww is 1.

Proof.

We are going to proceed by induction. First, notice that for b12b12- and b111treeb111-tree there exists ww a leaf such that the weight of the adjacent edge to ww is 1.
Let GG be a trivalent graph, if we perform O1O1 in one of its vertices, we are attaching a b111treeb111-tree by one of its white vertices, letting 2 white vertices free that are going to be leaves of GG with such that the weight of the adjacent edges to them is 1.
On the other hand, if we perform O2O2 in one of GG’s vertices, we are attaching a b12treeb12-tree to it by the only white vertex whose adjacent edge weight is 2, therefore the white vertex whose adjacent edge weight is 1, is now a leaf of the new graph
Finally, if we perform O1O1^{*} to GG and other graph, by definition we take a b111treeb111-tree and attach one white vertex to GG, one to the other graph and the last one is free, which is the leaf whose adjacent edge weight is 1.
Since the process to get any trivalent graph is taking b12b12 or b111b111 and performing O1,O2O1,O2 or O1O1^{*}, as many times as we want in each step we have a leaf whose adjacent edge weight is 1, therefore the resulting trivalent graph has it. ∎

Remark.

Let GG be a trivalent graph with kk white vertices, the resulting trivalent graph GG^{\prime} after performing O1O1 in any white vertex of GG has k+2k+2 white vertices.

Remark.

Let GG be a trivalent graph with kk white vertices, the resulting trivalent graph GG^{\prime} after performing O2O2 in any white vertex of GG has k+1k+1 white vertices.

Remark.

Let GG and GG^{\prime} be trivalent graphs with kk and jj white vertices, respectively. The resulting graph HH after performing O1O1^{*} in any pair of white vertices of GG and GG^{\prime} has k+j+1k+j+1 white nodes.

Using the previous remarks we have the following theorem:

Theorem 5.2.

For any nn an integer greater than 3. The list of all the trivalent graphs with nn white vertices, (including isomorphisms) will be obtained by performing the operation O1O1 to all the trivalent graphs with n2n-2 white vertices in each of their white vertices, performing the operation O2O2 to all the trivalent graphs with n1n-1 white nodes in each of their vertices and finally for every mm, such that 2mn32\leq m\leq n-3 perform the operation O1O1^{*} in all the pairs of white vertices of every pair of trivalent graphs where the first one is an element of the list of trivalent graphs with mm white vertices and the second one is an element of the list of trivalent graphs with nm1n-m-1 white vertices.

Proof.

Let nn be an integer greater than 3. By the remarks, it is clear that performing the algorithm described will give us a subset of the list of all the trivalent graphs with nn white vertices. Let’s see that this subset is the total set.
Let GG be a trivalent graph with n>3n>3 white vertices and ww a leaf of GG such that the edge adjacent to ww has weight 1, it exists by lemma 5.1. We know that ww is a white vertex, by theorem 1 in [7]. Let bb be the black node adjacent to ww. If bb has degree 2, let vv be the other vertex adjacent to bb, when we erase the vertices w,bw,b we get a new graph GG^{\prime} with n1n-1 white vertices such that after performing O2O2 in GG^{\prime} in the vertex vv we get GG.
If bb has degree 3, then bb is part of a b111subtreeb111-subtree, and let v1v_{1} and v2v_{2} the vertices adjacent to bb different to ww. If there is viv_{i} (i1,2i\in{1,2}) such that its degree is one, suppose v1v_{1}, when we erase the vertices w,b,v1w,b,v_{1}, we get a new trivalent graph GG^{\prime} with n2n-2 white vertices such that after performing O1O1 in v2v_{2} we get the original trivalent graph GG. On the other hand when neither v1v_{1} nor v2v_{2} has degree 1, when we erase the vertices b,wb,w we get two trivalent graphs HH and HH^{\prime} such that the sum of their white vertices is n1n-1 and after performing O1O1^{*} in v1,v2v_{1},v_{2} we get the original graph GG.
Therefore every trivalent graph of the list was a result of a step in the algorithm described in the theorem and the algorithm gives us all the graphs, including isomorphisms.

nn Total Created
2 1 1
3 3 3
4 6 11
5 18 37
6 51 150
7 167 573
8 551 2267
9 1954 8997
10 7066 36498
11 26486 149708
Table 1: Number of distinct graphs we got for each value nn (the number of white vertices), and the number of graphs that were created to construct them all.

This process is exhaustive, we can assure that it creates all the trivalent graphs with nn white vertices, but it creates too many repetitions. This is because there are symmetries in the rooted trivalent graphs, and when applying any operation in two symmetric vertices the resulting trivalent graph is the same.

Definition 5.3.

Given GG a rooted trivalent graph, we say that two vertices u,vGu,v\in G are symmetric if there exists an automorphism ϕ:GG\phi:G\to G (as rooted weighted graphs) such that ϕ(u)=v\phi(u)=v.

It is clear that if two vertices are symmetric, they must have the same string representation because the string representation of a vertex vv depends solely on the isomorphisms class of the subtree defined by the descendants of vv. Unfortunately, having the same string representation is not enough to recognize symmetric vertices. The fathers of two symmetrical vertices uu and vv must be symmetrical as well ( an automorphism ϕ:GG\phi:G\to G must send the father of uu to the father of vv). This implies, that the process of detecting symmetrical vertices can be iterated recursively, and it will end when the fathers of two vertices coincide (when they are siblings).

We use the above idea for detecting symmetric white vertices of a graph GG. And we modified algorithm 7 to work only with symmetrically distinct white vertices. These changes reduced the number of generated graphs by around 20%20\% as shown in Table 2.

nn Created Reduction
4 11 0,00%
5 32 13,51%
6 122 18,67%
7 467 18,50%
8 1781 21,44%
9 7099 21,10%
10 28852 20,95%
11 119168 20,40%
Table 2: Number of created graphs after considering symmetrically distinct white vertices.

More optimization could’ve been done to avoid so many repetitions, but the program would’ve run in exponential time anyway. Because the number of graphs we want to construct has exponential growth.

6 Nomenclature

We need a nomenclature to differentiate the trivalent graphs. For GG a trivalent graph, the tag is going to be the identifier of GG. To have a general idea of the shape of the graph it is necessary to include the number of leaves, black and white nodes. Also, we will include the length of the largest and shortest leaf paths of GG. And an ID number that identifies GG as a unique graph.
Denote W(G),B(G),L(G)W(G),B(G),L(G) the sets of white vertices, black vertices and leaves of GG, respectively.
The tag will have the following structure:

tag(G)tag(G) = [ |W(G)||W(G)|, |B(G)||B(G)|, |L(G)||L(G)|, length(shortest leaf path), length(largest leaf path), ID number]

The IDID number is automatically generated by the program when using the Hash table that uses the unique string representation of GG to order it in the list of trivalent graphs.

References

  • [1] Trivalent stratifold repository.
  • [2] Alfred V. Aho, John E. Hopcroft, and Jeffrey D. Ullman. The design and analysis of computer algorithms. Addison-Wesley Publishing Co., Reading, Mass.-London-Amsterdam, 1975. Second printing, Addison-Wesley Series in Computer Science and Information Processing.
  • [3] Douglas M. Campbell and David Radford. Tree isomorphism algorithms: speed vs. clarity. Math. Mag., 64(4):252–261, 1991.
  • [4] Gary Chartrand and Ping Zhang. Chromatic graph theory. Discrete Mathematics and its Applications (Boca Raton). CRC Press, Boca Raton, FL, 2009.
  • [5] J. C. Gómez-Larrañaga, F. González-Acuña, and Wolfgang Heil. 2-dimensional stratifolds. In A mathematical tribute to Professor José María Montesinos Amilibia, pages 395–405. Dep. Geom. Topol. Fac. Cien. Mat. UCM, Madrid, 2016.
  • [6] J. C. Gomez-Larrañaga, F. González-Acuña, and Wolfgang Heil. Classification of simply-connected trivalent 2-dimensional stratifolds. Topology Proc., 52:329–340, 2018.
  • [7] J. C. Gomez-Larrañaga, F. González-Acuña, and Wolfgang Heil. Models of simply-connected trivalent 2-dimensional stratifolds. Bol. Soc. Mat. Mex., 26:1301––1312, 2020.
  • [8] Hernández Yair. Stratifolds. https://github.com/yair-hdz/stratifolds, 2018.