The Number of Euler Tours of A Random D-In/d-Out Graph: P Aid I Creed and Mary Cryan
The Number of Euler Tours of A Random D-In/d-Out Graph: P Aid I Creed and Mary Cryan
The Number of Euler Tours of A Random D-In/d-Out Graph: P Aid I Creed and Mary Cryan
In this paper we obtain the expectation and variance of the number of Euler tours of a random d-in/d-out directed
graph, for d ¥ 2. We use this to obtain the asymptotic distribution and prove a concentration result. We are then able
to show that a very simple approach for uniform sampling or approximately counting Euler tours yields algorithms
running in expected polynomial time for almost every d-in/d-out graph. We make use of the BEST theorem of de
Bruijn, van Aardenne-Ehrenfest, Smith and Tutte, which shows that the number of Euler tours of a d-in/d-out graph
is the product of the number of arborescences and the term rpd 1q!sn {n. Therefore most of our effort is towards
estimating the asymptotic distribution of the number of arborescences of a random d-in/d-out graph.
1 Introduction
Let G pV, E q be a directed graph. An Euler tour of G is any ordering eπp1q , . . . , eπp|E |q of the set of
arcs E such that for every 1 ¤ i |E |, the target vertex of arc eπpiq is the source vertex of eπpi 1q , and
such that the target vertex of eπp|E |q is the source of eπp1q . We use ET pGq to denote the set of Euler tours
of G, where two Euler tours are considered to be equivalent if one is a cyclic permutation of the other. It
is a well-known fact that a directed graph G has an Euler tour if and only if G is connected and if for each
v P V , the in-degree and out-degree of v are equal.
In this paper, we are interested in the number of Euler tours of a random d-in/d-out graph. Let Gnd,d
be the space of all d-in/d-out graphs on n vertices. We will consider the problem of determining the
asymptotic distribution of the number of Euler tours of a random G P Gnd,d . Similar results have been
obtained for a variety of structures in uniformly random d-regular undirected graphs, e.g., Hamiltonian
cycles [13, 14, 6], 1-factors [10], and 2-factors [12]. In each of these results, one of the goals was to prove
that the structure of interest occurs in G with high probability when G is chosen uniformly at random from
the set of all undirected d-regular graphs. Since every connected d-in/d-out graph has an Euler tour, the
existence question is not of interest here. In the case of Hamiltonian cycles the asymptotic distribution was
further used by Frieze et al.[6] to prove that very simple algorithms for random sampling and approximate
counting of Hamiltonian cycles run in expected polynomial time for almost every d-regular graph. This
paper contains analogous counting and sampling results for Euler tours of d-in/d-out graphs for d ¥ 2.
c by the authors Discrete Mathematics and Theoretical Computer Science (DMTCS), Nancy, France
subm. to DMTCS °
2 Páidı́ Creed and Mary Cryan
Our result uses a well-known relationship between the Euler tours and arborescences of a graph. An
arborescence of a directed graph G pV, E q is a rooted spanning tree of G in which all arcs are directed
towards the root. We will use ARBS pGq to denote the set of arborescences of G and, for any v P V , use
ARBS pG, v q to denote the set of arborescences rooted at v. For any Eulerian directed graph G, the BEST
Theorem (due to de Bruijn and van Aardenne-Ehrenfest [18], extending a result of Smith and Tutte [15])
reduces the problem of computing |ET pGq| to the problem of computing |ARBS pG, v q|, for any vertex
v PV.
Theorem 1 ([15, 18]) Let G pV, E q be an Eulerian directed graph. For any v P V , we have
¹
|ET pGq| poutdegpuq 1q! |ARBS pG, vq| . (1)
P
u V
We remark that the above theorem enables exact counting or sampling of Euler tours of any directed
graph in polynomial time, as both these tasks can be carried out in polynomial time for arborescences of
any directed graph [17, 4, 11]. The simple algorithms for uniform sampling and approximate counting
we consider in Section 4, have so far only been analysed for Eulerian tournaments, in [9] (as part of their
analysis of Euler tours on the undirected complete graph with an odd number of vertices).
We generate graphs using a directed version of the configuration model [2, 3]. We define the configura-
n as follows. Let Sv and Tv , 1 ¤ v ¤ n, be disjoint d-sets and let S YSv and T YTv .
tion space Φd,d
We say Sv is the set of configuration points available for arcs leaving v and Tv is the set of points avail-
able for arcs entering v. A configuration F is a perfect matching from S to T and Φd,d n is the set of all
configurations. Note that | Φd,d
n | p dnq!. Each configuration F P Φ d,d
n projects to a directed d-in/d-out
pseudo-graph σ pFq by identifying the elements of Sv and Tv . That is, σ pFq has an arc pu, v q for each pair
from Su Tv that is contained in F. This model has been analysed in the past for the case when d 2
in [1, Section 7], to obtain an estimate of the expected number of Euler tours of a random G P Gnd,d . One
nice property of the model, and of the original configuration model, is that directed graphs (without loops
or double arcs) are generated with equal probability. Hence, by studying properties of uniformly random
configurations we can infer results about uniformly random elements of Gnd,d by conditioning on there
being no loops or double arcs.
The results in this paper are of an asymptotic nature. If an and bn are sequences of numbers, we take
an bn to mean limnÑ8 an {bn 1. Given a sequence of random variables Xn and random variable
Z defined on the same probability space Ω, we say Xn converges in distribution to Z, or Z has the
asymptotic distribution of Xn , if
lim PrXn xs PrZ xs , @x P Ω .
nÑ8
The proof idea we use in this paper is that of conditioning on short cycle counts, pioneered by Robinson
and Wormald in [13, 14]. Implicit in this pair of papers (and the subsequent work of Frieze et al. [6])
is a characterisation of the asymptotic distribution of the number of Hamiltonian cycles in a random d-
regular graph in terms of random variables counting the number of i-cycles, for all fixed positive integers
i. Janson [7] streamlined the technique of Robinson and Wormald and proved a general theorem (stated
here as Theorem 4). In Section 3, we use Theorem 4 to obtain an asymptotic distribution for the number
of Euler tours of a random d-in/d-out graph.
In some places in the paper we only give proof sketches. For more detailed proofs, and some results for
the more general model for in-degree/out-degree sequences d~ pd1 , . . . , dn q, see [5].
The number of Euler tours of a random d-in/d-out graph 3
Fact 1 Falling factorial powers of sums obey the well known multinomial theorem
l
¸ k ¹
px1 x2 xl qk ° δ1 , . . . , δl i1
pxi qδi ,
δi k
where the sum is taken over all partitions of k into l non-negative integer parts.
Fact 2 (see, e.g., [16]) Let V t1, 2, . . . , nu. The number of k-forests on V in which v has δv children
is
n1 nk
.
k 1 δv : v P V
We use Fact 1 and Fact 2 to prove the following lemma. In this lemma, and in the proofs of subsequent
results, we will speak of a configuration for an (in-directed) arborescence or forest. We take this to mean
a partial matching from S to T (in the configuration model) that projects to a arborescence or forest.
Lemma 1 Suppose we have a set of vertices V t1, 2, . . . , nu for which there are xv points for arcs
entering v P V and yv points for arcs leaving v P V , with xv not necessarily equal to yv . Then, the
number of ways to choose a configuration for an in-directed forest rooted at R V is
¹ ¸ ¸
yv xv xv 1 . (2)
R
v R P
v R v V P |R|1
n
Proof: Let F be a forest on t1, 2, . . . , nu rooted at R and let δv be the number of children of v in F, for
each v P V . The number of ways to choose points for the source and target vertex of each arc in F is
¹ ¹
yv pxv qδ v , (3)
R
v R P
v V
since we must choose a point for the start of the arc directed away from each v R R and choose one of the
° the end of each of the δv arcs directed towards each v P V .
xv points for
Let k vPR δv . We can construct a forest rooted at R by first choosing a k-forest on V R, and then
attaching each root of this forest as a child of some v P R. By Fact 2, the number of k-forests on V R
in which v P V R has exactly δv children is
n |R | 1 n |R | k
, (4)
k1 δv : v P V R
4 Páidı́ Creed and Mary Cryan
and the number of ways to divide the roots of this forest amongst the members of R so that each v P R
has δv children is
k
. (5)
δv : v P R
Combining (3), (4) and (5) and summing over all possible values for δv gives
¹ | | n |R| 1
n ¸R ¸
k
¹
yv k 1
δ : v P R
pxv qδv
R k1 v PR δv k
v PR
° v
v R
¸ n |R | k ¹
° δv : v R R
pxv qδ v
. (6)
R
v R |R|k
δv n R
v R
By Fact °
1, we see that the
°two sums over the different δv in (6) are expansions of the falling factorial
powers p vPR xv qk and p vRR xv qn|R|k , respectively. Hence, (6) is equal to
n|R|
¹ ¸ n |R| 1
p ¸ x q p ¸ x q
yv v n|R|k .
k1
v k
R
v R
k 1 v PR v PR
s
σ pAq is an arborescence of σ pF q. In the following proofs, we will abuse terminology slightly and switch
between speaking of arborescences of configurations and directed graphs arbitrarily.
Theorem 2 Let d be some fixed integer, d ¥ 2, and let An denote the number of arborescences (rooted
at any vertex) of a uniformly random F P Φd,d
n . Then,
ErAn s dn1 ;
ErpAn q2 s d2n1 .
n
dn n 1
Proof: To calculate the first moment of An we need to enumerate pairs pF, Aq, where F P Φd,d n and A is
an arborescence of F, and then divide by | Φd,d
n | . Given A, it is easy to count the number of configurations
F A: there are exactly dn n 1 arcs not contained in any particular arborescence of a d-in/d-out
graph, and hence pdn n 1q! ways to choose a configuration for those arcs. Applying Lemma 1 with
xv yv d for all v P V tells us that the number of arborescences rooted at any particular vertex is
dn pdn 1qn2 .
Multiplying this by npdn n 1q!, and dividing by the total number of configurations, pdnq!, gives the
claimed value for ErAn s.
To find the second moment, we need to count the number of ways to choose triples pF, A, A1 q, where
F P Φd,d 1
n and A and A are both arborescences of F. We approach this task by first counting partial config-
urations for the intersection A X A1 . We suppose pA, A1 q is a pair of arborescences of some configuration
The number of Euler tours of a random d-in/d-out graph 5
F and that F A X A1 is a forest with l components. By Lemma 1 (with xv yv d), the number of
possibilities for F is
n nl 1
d lpdn 1qnl1 . (7)
l
For each t 1 . . . l, let F t denote the t-th component of F, and let nt be the number of vertices in F t .
Then the total number of points available for arcs directed towards vertices of F t is xt pd 1qnt 1.
We choose the rest of A and A1 as follows. For t 1 . . . l, we contract each F t to a single vertex t. Now,
choosing configurations for the rest of A and A1 is equivalent to choosing configurations for a pair of
disjoint trees on t1, 2, . . . , lu, with d points available for arcs directed away from t and xt points available
for arcs directed towards t, for t 1 . . . l.
There are two cases. First suppose Fr is the component containing the root of A, Fr1 is the component
containing the root of A1 , and r r1 . Assume we have already chosen A such that A z A1 contains δt
arcs directed towards vertices in F t in A. Then, by Lemma 1, the number of ways to choose A1 z A is
and therefore the number of ways to complete F to A Y A1 is equal to dl pd 1ql2 pdn nql2 times
l
¸ l2 ¹
xr1
δr 1; δt : t r t1
pxt qδt
|δ |l1,δr ¥1
l
¸ l3 ¹
pl 2q δr 1, δr1 1; δt : t R tr, r u t1
1 pxt qδt . (8)
|δ |l1,δr ,δr1 ¥1
Using Fact 1, we can simplify the expression for the number of ways to complete F to A Y A1 to be
Multiplying (9) and (10) by pd 1q2 and dpd 1q, respectively, and summing over r and r1 gives
n n l
d pd 1ql pdnq! (11)
l n
6 Páidı́ Creed and Mary Cryan
which over-counts the number of triples pF, A, A1 q by weighting pF, A, A1 q by dpd 1q if A and A1 are
rooted at the same vertex, and by pd 1q2 if A and A1 have different roots.
From the BEST Theorem (Theorem 1), we know that the number of triples pF, A, A1 q in which A is
rooted at r and A1 is rooted at r1 does not depend on the choice of r and r1 . Thus, it follows that the factor
by which (11) over-counts the number of triples is
ErpAn q2 s d2n1 .
n n
pdn n 1q2
dn
l
lpd 1ql dn nn 1
l 1
l
Recall that simple directed graphs are generated with equal probability in the configuration model.
Thus, by conditioning on σ pF q containing no loops or 2-cycles, we can infer the first two moments of the
number of arborescences of a uniformly random G P Gnd,d . We provide a sketch below in Theorem 3. For
a detailed proof, see Section 3.3.1 of [5].
Theorem 3 Let d be some fixed constant, d ¥ 2, and let An denote the number of arborescences of a
uniformly random G P Gnd,d . Then,
ErAn s e1 dn1 ;
Proof: Let Ln and Dn denote random variables counting the number of loops and double edges in σ pFq
n . The directed graph σ pFq is simple precisely when
when F is chosen uniformly at random from Φd,d
Ln pFq Dn pFq 0; that is,
ppdq2i qj pdnpdnqk! q! .
¹
d
pnqj 1 j2 ,... jd
i
i 1
°d
Since k i1 iji , this value is Opnj2 2j3 pd1qjd q. Hence, the only terms in pLn qk which have
non-negligible contribution, as n Ñ 8, are those where each vertex has at most one loop. This means
that, for every k, ErpLn qk s dk , so Ln converges to a Poisson random variable with mean d. A similar
argument shows that Dn converges to a Poisson random variable with mean pd 1q2 {2, and that the
asymptotic distributions of Ln and Dn are independent. Hence, we have PpLn Dn 0q exppd
pd 1q2 {2q.
The number of Euler tours of a random d-in/d-out graph 7
p1q p1q
Now, let Ln An Ln and Dn An Dn . These random variables count the number of loops and
double edges in σ pF q weighted by the number of arborescences. This is equivalent to considering the
number of loops or double edges in F when F is obtained by choosing a uniformly random element of
s tpF, Aq : F P Φd,d
Φ n , A P ARBS pF qu .
First, suppose we have a loop at v in F . A loop edge cannot be contained in any arborescence of σ pF q,
so we can repeat the argument from Theorem 2, except with one vertex having in/out-degree d 1, giving
p1q
ErLn s d 1.
Now, suppose we have a pair of edges in F , e, f P Su Tv , for some u v. Note that there are
2
2 d2 pnq2 ways to choose e and f . The number of arborescences rooted at u, which can be extended to
pF, Aq pairs where F contains e and f , is equal to the number of arborescences rooted at u in a model
where there are d 2 points available for arcs directed towards v, d points available for arcs directed
towards each w v, and d points available for arcs directed away from each w u. By Lemma 1, this
number is dn pdn 3qn2 . There are exactly pdn n 1q! ways to extend each such arborescence to a
p1q
configuration containing e and f , and hence we can conclude that ErDn s pd 1q2 {2. Moreover, Ln
p 1q
p 1q
and Dn are in fact asymptotic to independent Poisson random variables. Hence, we can conclude that
Theorem 4 (Janson [7]) Let λi ¡ 0 and δi ¥ 1, i 1, 2, . . . , be constants and suppose that for each
n there are random variables Xin , i 1, 2, . . . , and Yn (defined on the same probability space) such that
Xin is non-negative integer valued and ErYn s 0 (at least for large n) and furthermore the following
conditions are satisfied:
1. Xin Ñ Xi8 (in distribution) as n Ñ 8, jointly for all i, where Xi8 is a Poisson random variable
with mean λi ;
2. For any finite sequence x1 , . . . xk of non-negative integers
°
3. i λi δi2 8;
4.
r s
E Yn2
Ñ expp°i λi δi2 q;
r s
E Yn 2
Then
8
¹
δi qXi8 eλi δi .
Yn
ErYn s
ÑW p1
i 1
Moreover, this and the convergence in 1 holds
° jointly. The infinite product defining W converges a.s. and
in L2 , with ErW s 1 and ErW 2 s expp i λi δi2 q limnÑ8 ErYn s2 {ErYn s2 . Hence, the normalised
variables are uniformly square integrable. Furthermore, the event W ¡ 0 equals, up to a set of probability
0, the event that Xi8 ¡ 0 for some i with δi 1. In particular, W ¡ 0 a.s. if and only if every δi ¡ 1.
In our application of Theorem 4 we will have Yn T n , the random variable counting Euler tours of
d-in/d-out graphs, and Xin equal to the number of directed i-cycles in a random d-in/d-out graph. To
apply Theorem 4 we need the following two lemmas.
Lemma 2 For each positive integer i let Xin count the number of directed i-cycles in a directed graph
obtained as the projection of a uniformly random F P Φd,d
n . The variables Xin are asymptotically inde-
pendent Poisson random variables with means ErXin s λi di .
i
pdn iq! 1 .
pdnq! pdnqi
So, to estimate ErXin s all we need to do is count the number of different i-cycles that can occur in some
F P Φd,d
n and then divide by pdnq . Let I be some i-subset of t1, 2, . . . , nu. There are pi 1q! different
i
ways to arrange I into an i-cycle pv1 , v2 , . . . , vi q and then d2i ways to choose edges ej P Svj Tvj 1 for
1 ¤ j i and ei P Svi Tv1 . Hence,
ErXin s
pi 1q! n 2i
pdnqi i d ,
The number of Euler tours of a random d-in/d-out graph 9
and so ErXin s λi . The contribution to ErpXin qk s from configurations in which there are s in-
tersections between i-cycles is Opns q. Hence, we can assume that cycles occur independently and
ErpXin qk s pλi qk , for every k, so Xin converges to a Poisson random variable with mean λi . Moreover,
by a similar argument, we can show that products of factorial moments converge,
¹̀ ¹̀
E pXin qk
i λki i ,
i 1
i 1
whence the asymptotic distributions of the Xin are independent Poisson variables. l
Lemma 3 Let Xin be as in Lemma 3 and let µi d i1 . Then, for any fixed set of integers j1 , j2 , . . . , jk
i
we have
±k
ErAn i1 pXin qji s ¹ ji
k
ErAn s
µi .
i1
We now have sufficient ammunition to apply Janson’s theorem and obtain an asymptotic distribution for
the number of Euler tours of a uniformly random G P Gnd,d .
Theorem 5 Let d ¥ 2 be some fixed integer, and let T n denote the number of Euler tours in a directed
graph G chosen uniformly at random from Gnd,d . Then,
8
¹
Z i
e1{i ,
Tn 1
ErT n s
1
di
i 2
where the Zi are independent Poisson random variables with means di {i.
Proof: It suffices to show that conditions (1) to (4) of Theorem 4 are satisfied by T n and tXin : i ¥ 2u,
where Xin is the random variable counting i-cycles. Lemma 2 and Corollary 2 provide conditions (1) and
(2) with
di 1
λi and δi i .
i d
With these values, evaluating the sum in condition (3) gives
8̧ 1
idi
d1 log
d
d1
. (13)
i2
This procedure was first considered in [9], where the authors showed it terminates in expected polynomial
time when G Kn for odd n. If G P Gnd,d then (14) becomes d|ET pGq|{pd!qn . The following theorem
uses the results of the previous section (by a similar argument to that used in [6, Lemma 1]) to show that
this value is Ωpn2 q with high probability when G is chosen uniformly at random from Gnd,d . When this
is the case, we can generate uniformly random Euler tours of G in expected polynomial time. Moreover,
by generating a number of samples and recording the proportion of executions which yielded Euler tours,
we can approximate |ET pGq|.
Theorem 6 Let d be some fixed integer, d ¥ 2, and let G be chosen uniformly at random from Gnd,d . Then,
P
|ET pGq| P Ωpn2 q Ñ 1 ,
pd!qn
as n Ñ 8.
The number of Euler tours of a random d-in/d-out graph 11
Proof: We first note that by the estimate for ErT n s given in Corollary 1, the statement above is equivalent
to showing that
P
| T n | P Ωpn1 q Ñ 1 .
ErT n s
We will combine our results to date to derive this statement. For x px2 , . . . , xk q we define Gx to be the
set of all d-in/d-out graphs containing exactly xi directed cycles of length i for each i 2 . . . k, and
x i
¹
k
e1{i .
1
W pxq 1
i 2 di
The sum inside the exponential is clearly convergent, so we can conclude that A ¥ eb for some absolute
constant b. Similarly, we can bound B by
8̧ 1
B ¥ exp ,
piq d
2{3 i{3
i 2
and, again, the sum in the exponential is convergent, so B γ ¥ ecγ for some absolute constant c. l
12 Páidı́ Creed and Mary Cryan
5 Acknowledgements
This work has benefited from conversations with Kyriakos Kalorkoti. The original idea for applying
Robinson and Wormald’s technique to the number of Euler tours came from Alan Frieze.
References
[1] Richard Arratia, Béla Bollobás, Don Coppersmith, and Gregory B. Sorkin. Euler circuits and DNA
sequencing by hybridization. Discrete Applied Mathematics, 104(1-3):63–96, 2000.
[2] Edward A. Bender and E. Rodney Canfield. The Asymptotic Number of Labeled Graphs with Given
Degree Sequences. Journal of Combinatorial Theory, Series A, 24(3):296–307, 1978.
[3] Béla Bollobás. A probabilistic proof of an asymptotic formula for the number of labelled regular
graphs. European Journal of Combinatorics, 1:311–316, 1980.
[4] Charles J. Colbourn, Wendy J. Myrvold, and Eugene Neufeld. Two Algorithms for Unranking
Arborescences. Journal of Algorithms, 20(2):268–281, 1996.
[5] Patrick J. Creed. Counting and Sampling problems on Eulerian graphs. PhD thesis, School of
Informatics, University of Edinburgh, 2010. Submitted.
[6] Alan M. Frieze, Mark Jerrum, Michael Molloy, Robert W. Robinson, and Nicholas C. Wormald.
Generating and Counting Hamilton Cycles in Random Regular Graphs. Journal of Algorithms,
21(1):176–198, 1996.
[7] Svante Janson. Random Regular Graphs: Asymptotic Distributions and Contiguity. Combinatorics,
Probability & Computing, 4:369–405, 1995.
[8] Svante Janson, Tomasz Łuczak, and Andrzej Riciński. Random Graphs. Wiley, 2000.
[9] Brendan D. McKay and Robert W. Robinson. Asymptotic Enumeration of Eulerian Circuits in the
Complete Graph. Combinatorics, Probability & Computing, 7(4):437–449, 1998.
[10] Michael S. O. Molloy, Hanna D. Robalewska, Robert W. Robinson, and Nicholas C. Wormald. 1-
Factorizations of random regular graphs. Random Structures and Algorithms, 10(3):305–321, 1997.
[11] James Gary Propp and David Bruce Wilson. How to Get a Perfectly Random Sample From a Generic
Markov Chain and Generate a Random Spanning Tree of a Directed Graph. Journal of Algorithms,
27:170–217, 1998.
[12] Hanna D. Robalewska. 2-factors in random regular graphs. Journal of Graph Theory, 23(3):215–
224, 1996.
[13] Robert W. Robinson and Nicholas C. Wormald. Almost All Cubic Graphs Are Hamiltonian. Random
Structures & Algorithms, 3(2):117–126, 1992.
[14] Robert W. Robinson and Nicholas C. Wormald. Almost All Regular Graphs Are Hamiltonian. Ran-
dom Structures & Algorithms, 5(2):363–374, 1994.
The number of Euler tours of a random d-in/d-out graph 13
[15] C. A. B. Smith and W. T. Tutte. On unicursal paths in networks of degree 4. American Mathematical
Monthly, 48:233–237, 1941.
[16] Richard P. Stanley. Enumerative Combinatorics, volume 2. Cambridge University Press, 2001.
[17] W.T. Tutte. Graph Theory, Encyclopedia of Mathematics and it Applications, volume 21. Addison-
Wesley Publishing Company, 1984.
[18] Tanja van Aardenne-Ehrenfest and Nicholas G. de Bruijn. Circuits and trees in oriented linear
graphs. Simon Stevin, 28:203–217, 1951.