# Counting paths in perfect trees

We present some exact expressions for the number of paths of a given length in a perfect m-ary tree. We first count the paths in perfect rooted m-ary trees and then use the results to determine the number of paths in perfect unrooted m-ary trees, extending a known result for binary trees.

## Authors

• 1 publication
08/31/2018

### How to Fit a Tree in a Box

We study compact straight-line embeddings of trees. We show that perfect...
08/22/2019

### Exact inference under the perfect phylogeny model

Motivation: Many inference tools use the Perfect Phylogeny Model (PPM) t...
11/03/2018

### Efficient Projection onto the Perfect Phylogeny Model

Several algorithms build on the perfect phylogeny model to infer evoluti...
07/12/2020

### Perfect Sampling of Multivariate Hawkes Process

As an extension of self-exciting Hawkes process, the multivariate Hawkes...
12/02/2019

### A Generalized Matrix-Tree Theorem for Pfaffian Pairs

The matrix-tree theorem counts the number of spanning trees of undirecte...
04/19/2018

### A third strike against perfect phylogeny

Perfect phylogenies are fundamental in the study of evolutionary trees b...
09/17/2018

### Binary Proportional Pairing Functions

A pairing function for the non-negative integers is said to be binary pe...
##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 1. Introduction

A tree is a connected acyclic graph with a finite vertex set and finite edge set . The distance between two vertices is the number of edges in the (unique) path in that joins and . In this paper, we focus on counting the pairs of vertices that are some given distance apart, or equivalently the paths of a given length, in a perfect tree.

Given a tree , let denote the number of pairs of vertices at distance exactly from each other. That is,

 P(T,t)=∣∣∣{{u,v}∈(V2):dT(u,v)=t}∣∣∣and∑t≥1P(T,t)=|V|(|V|−1)2.

Note immediately that . Furthermore, from the observations that each vertex of degree is the central vertex of distinct paths of length and that each edge is the central edge of distinct paths of length , we obtain

 P(T,2)=∑v∈V(deg(v)2)andP(T,3)=∑{u,v}∈E(deg(u)−1)(deg(v)−1).

Similar expressions for when become increasingly complicated.

Faudree et al. [3] constructed examples showing that two non-isomorphic trees can have identical path length distributions (that is, for all ). Tight upper and lower bounds for were given by Dankelmann [1] in terms of and either the radius or diameter of .

A binary tree , in which every vertex has degree or degree , is perfect (or balanced) if has the maximum number of vertices among all binary trees of the same diameter. De Jong et al. [2] used a recursive approach to show that the perfect binary tree of diameter with degree- vertices has

 P(T,t)=⎧⎪ ⎪ ⎪⎨⎪ ⎪ ⎪⎩2t+12(n−3⋅2t−32),t odd,3⋅2t2−1(n−2t2),t even

paths of length for .

We adopt a different approach to extend this to perfect -ary trees, where each vertex has degree or . In particular, we prove the following theorem.

###### Theorem 1.1.

Let be the perfect unrooted -ary tree of diameter . Then, for ,

 P(T,t) =⎧⎨⎩mt−12(V(D)−V(t−1)),t odd,12(m+1)mt2−1(V(D)−V(t−1)),t even,

where is the number of vertices in the perfect unrooted -ary tree of diameter .

We first derive an analogous theorem for perfect rooted -ary trees, where the root has degree and all other vertices have degree or . Theorem 1.2 is obtained in Section 2 by counting the paths of length in a perfect rooted

-ary tree according to minimum depth, considering odd

and even separately.

###### Theorem 1.2.

Let be the perfect rooted -ary tree of depth , and let satisfy . If is odd, then

 P(T,t) =⎧⎪⎨⎪⎩mt−12(VR(r)−VR(t−12))−t−12mt−1,t≤r,mt−12(VR(r)−VR(t−12))−(r−t−12)mt−1,t>r,

and if is even, then

 P(T,t) =⎧⎪⎨⎪⎩12(m+1)mt2−1(VR(r)−VR(t2−1))−t2mt−1,t≤r,12(m+1)mt2−1(VR(r)−VR(t2−1))−(r−t2+1)mt−1,t>r,

where is the number of vertices in the perfect rooted -ary tree of depth .

In Section 3, we use the results from Section 2 to prove Theorem 1.1.

## 2. Perfect rooted m-ary trees

In a rooted -ary tree , there is a distinguished vertex of degree called the root, while every other vertex has degree or . The depth of is the maximum value of over all vertices . We call perfect if and only if every degree- vertex is distance from the root .

Let be the perfect rooted -ary tree of depth . For , there are exactly vertices for which . Let be a path of length in . Then there is a unique vertex , , such that for all . We call a type- path rooted at .

###### Lemma 2.1.

Let be the perfect rooted -ary tree of depth . If , then the number of type- paths in rooted at is . If , then the number of type- paths in rooted at is

 ⎧⎪ ⎪⎨⎪ ⎪⎩mt,s=0,(m−1)mt−1,0
###### Proof.

The case is obvious, as is the case with . Assume that and that . Then any type- path can be decomposed into a type- path rooted at and a type- path rooted at , where these two paths are disjoint. There are choices for the type- path. Once this choice has been made, there are choices for the type- path, so the total number of type- paths rooted at is . If , then this argument counts each type- path twice, hence the third equality. ∎

Let denote the number of paths of length in the perfect rooted -ary tree of depth . The preceding lemma can be used to derive exact expressions for . We consider paths of odd length and paths of even length separately, and make repeated use of the identity

 b∑i=ami=mb+1−mam−1.
###### Proposition 2.2.

The number of paths of length in the perfect rooted -ary tree of depth , where , is

 Pm(r,t)
###### Proof.

Let be the perfect rooted -ary tree of depth . If , then the longest path in has length , and so .

If and , then by Lemma 2.1, there are type- paths rooted at each vertex for which . Therefore,

 Pm(r,t) =(m−1)m2k−2k−1∑s=2k−r−1(r−2k+s−1∑d=0md) =(m−1)m2k−2k−1∑s=2k−r−1mr−2k+s+2−1m−1 =m2k−2r−k+1∑i=1(mi−1) =m2k−2(mr−k+2−1m−1−(r−k+2)).

If , then there are type- paths rooted at each vertex for which . Furthermore, for , there are type- paths rooted at each vertex for which . Therefore,

 Pm(r,t) =m2k−1r−2k+1∑d=0md+(m−1)m2k−2k−1∑s=1(r−2k+s+1∑d=0md) =m2k−2(m(mr−2k+2−1m−1)+(m−1)k−1∑s=1mr−2k+s+2−1m−1) =m2k−2(mr−2k+3−mm−1+r−k+1∑i=r−2k+3(mi−1)) =m2k−2(mr−2k+3−mm−1+mr−k+2−mr−2k+3m−1−(k−1)) =m2k−2(mr−k+2−1m−1−k).

###### Proposition 2.3.

The number of paths of length in the perfect rooted -ary tree of depth , where , is

 Pm(r,t) =⎧⎪⎨⎪⎩m2k−1(12(m+1)(mr−k+1−1m−1)−(r−k+1)),r<2k,m2k−1(12(m+1)(mr−k+1−1m−1)−k),r≥2k.
###### Proof.

Let be the perfect rooted -ary tree of depth . If , then the longest path in has length , and so .

If , then by Lemma 2.1, there are type- paths rooted at each vertex for which . Furthermore, for , there are type- paths rooted at each vertex for which . Therefore,

 Pm(r,t) =12(m−1)m2k−1r−k∑d=0md+(m−1)m2k−1k−1∑s=2k−r(r−2k+s∑d=0md) =m2k−1(12(m−1)(mr−k+1−1m−1)+(m−1)k−1∑s=2k−rmr−2k+s+1−1m−1) =m2k−1(12(mr−k+1−1)+r−k∑i=1(mi−1)) =m2k−1(12(mr−k+1−1)+mr−k+1−mm−1−(r−k)) =m2k−1(12(m+1)(mr−k+1−1m−1)−(r−k+1)).

If , then by Lemma 2.1, there are type- paths rooted at each vertex for which and type- paths rooted at each vertex for which . Furthermore, for , there are type- paths rooted at each vertex for which . Therefore,

 Pm(r,t) =12(m−1)m2k−1r−k∑d=0md+(m−1)m2k−1k−1∑s=1(r−2k+s∑d=0md)+m2kr−2k∑d=0md =m2k−1(12(m−1)(mr−k+1−1m−1)+(m−1)k−1∑s=1mr−2k+s+1−1m−1+m(mr−2k+1−1m−1)) =m2k−1(12(mr−k+1−1)+r−k∑i=r−2k+2(mi−1)+mr−2k+2−mm−1) =m2k−1(12(mr−k+1−1)+mr−k+1−mr−2k+2m−1−(k−1)+mr−2k+2−mm−1) =m2k−1(12(m+1)(mr−k+1−1m−1)−k).

Theorem 1.2 now follows by combining Propositions 2.2 and 2.3 with the observation that

 VR(d) =md+1−1m−1.

## 3. Perfect unrooted m-ary trees

In an unrooted -ary tree , every vertex has degree or . The diameter of is the maximum value of over all pairs of vertices . We call perfect if and only if every degree- vertex is distance from some other vertex.

The symmetry of a perfect unrooted -ary tree of diameter depends on whether is odd or even. We introduce some notation to be used in this respect. If is odd, then can be constructed by connecting the roots of two perfect rooted -ary trees of depth with an edge . If is even, then can be constructed by connecting the roots of the perfect rooted -ary tree of depth and the perfect rooted -ary tree of depth with an edge . In either case, a path in is either contained in , contained in , or contains .

Let denote the number of paths of length in the perfect unrooted -ary tree of diameter . We consider four cases, depending on the parities of and . The proofs of the propositions below make repeated use of Lemma 2.1 and Propositions 2.2 and  2.3.

###### Proposition 3.1.

The number of paths of length in the perfect unrooted -ary tree of diameter , where is

 Um(D,t) =m2k−2m−1(2mr−k+1−(m+1)).
###### Proof.

Let be the perfect unrooted -ary tree of diameter . We use the decomposition of into , , and . The number of paths in of length that contain is

 min{t−1,r−1}∑s=max{0,t−r}mt−1=⎧⎪⎨⎪⎩0,r

If , then . If , then the depth of (and of ) is , so . Also, , and hence . If , then , and so

 Um(D,t) =2Pm(r−1,2k−1)+(2r−2k+1)m2k−2 =2m2k−2(mr−k+1−1m−1−(r−k+1))+(2r−2k+1)m2k−2 =m2k−2m−1(2mr−k+1−(m+1)).

If , then , and so

 Um(D,t) =2Pm(r−1,2k−1)+(2k−1)m2k−2 =2m2k−2(mr−k+1−1m−1−(r−k+1))+(2k−1)m2k−2 =m2k−2m−1(2mr−k+1−(m+1)).

If , then , and so

 Um(D,t) =2Pm(r−1,2k−1)+(2k−1)m2k−2 =2m2k−2(mr−k+1−1m−1−k)+(2k−1)m2k−2 =m2k−2m−1(2mr−k+1−(m+1)).

###### Proposition 3.2.

The number of paths of length in the perfect unrooted -ary tree of diameter , where , is

 Um(D,t) =m2k−1m−1((m+1)mr−k−(m+1)).
###### Proof.

Using the decomposition of into , , and , the number of paths of length in that contain is

 min{t−1,r−1}∑s=max{0,t−r}mt−1=⎧⎨⎩0,r≤k,(2r−2k)m2k−1,k2k,

and again the result is immediate for . If , then , and so

 Um(D,t) =2Pm(r−1,2k)+(2r−2k)m2k−1 =m2k−1m−1((m+1)mr−k−(m+1)).

If , then , and so

 Um(D,t) =2Pm(r−1,2k)+2km2k−1 =m2k−1m−1((m+1)mr−k−(m+1)).

###### Proposition 3.3.

The number of paths of length in the perfect unrooted -ary tree of diameter , where , is

 Um(D,t) =m2k−2m−1((m+1)mr−k+1−(m+1)).
###### Proof.

Using the decomposition of into (depth ), (depth ), and , the number of paths of length paths in that contain is

 min{t−1,r}∑s=max{0,t−r}mt−1=⎧⎪⎨⎪⎩0,r

If , then . If , then , and so

 Um(D,t) =Pm(r,2k−1)+Pm(r−1,2k−1)+(2r−2k+2)m2k−2 =m2k−2(mr−k+2−1m−1−(r−k+2))+(2r−2k+2)m2k−2 =m2k−2m−1((m+1)mr−k+1−(m+1)).

If , then , and so

 Um(D,t) =Pm(r,2k−1)+Pm(r−1,2k−1)+(2r−2k+2)m2k−2 =m2k−2(mr−k+2−1m−1−(r−k+2))+m2k−2(mr−k+1−1m−1−(r−k+1)) +(2r−2k+2)m2k−2 =m2k−2m−1((m+1)mr−k+1−(m+1)).

If , then , and so

 Um(D,t) =Pm(r,2k−1)+Pm(r−1,2k−1)+(2k−1)m2k−2 =m2k−2(mr−k+2−1m−1−k)+m2k−2(mr−k+1−1m−1−(r−k+1))+(2k−1)m2k−2 =m2k−2m−1((m+1)mr−k+1−(m+1)).

If , then , and so

 Um(D,t) =Pm(r,2k−1)+Pm(r−1,2k−1)+(2k−1)m2k−2 =m2k−2(mr−k+2−1m−1−k)+m2k−2(mr−k+1−1m−1−k)+(2k−1)m2k−2 =m2k−2m−1((m+1)mr−k+1−(m+1)).

###### Proposition 3.4.

The number of paths of length in the perfect unrooted -ary tree of diameter , where , is

 Um(D,t) =m2k−1m−1(12(m+1)2mr−k−(m+1)).
###### Proof.

Using the decomposition of into (depth ), (depth ), and , the number of paths of length in that contain is

 min{t−1,r}∑s=max{0,t−r}mt−1=⎧⎨⎩0,r

and again the result is immediate for . If , then , and so

 Um(D,t) =Pm(r,2k)+Pm(r−1,2k)+(2r−2k+1)m2k−1 =m2k−1(12(m+1)(mr−k+1−1m−1)−(r−k+1))+(2r−2k+1)m2k−1 =m2k−1m−1(12(m+1)2mr−k−(m+1)).

If , then , and so

 Um(D,t) =Pm(r,2k)+Pm(r−1,2k)+(2r−2k+1)m2k−1 =m2k−1(12(m+1)(mr−k+1−1m−1)−(r−k+1)) +m2k−1(12(m+1)(mr−k−1m−1)−(r−k))+(2r−2k+1)m2k−1 =m2k−1m−1(12(m+1)2mr−k−(m+1)).

If , then , and so

 Um(D,t) =Pm(r,2k)+Pm(r−1,2k)+2km2k−1 =m2k−1(12(m+1)(mr−k+1−1m−1)−k) +m2k−1(12(m+1)(mr−k−1m−1)−(r−k))+2km2k−1 =m2k−1m−1(12(m+1)2mr−k−(m+1)).

If , then , and so

 Um(D,t) =Pm(r,2k)+Pm(r−1,2k)+2km2k−1 =m2k−1(12(m+1)(mr−k+1−1m−1)−k) +m2k−1(12(m+1)(mr−k−1m−1)−k)+2km2k−1 =m2k−1m−1(12(m+1)2mr−k−(m+1)).

Theorem 1.1 now follows by combining Propositions 3.1 to 3.4 with the observation that

 V(d)=⎧⎪ ⎪ ⎪⎨⎪ ⎪ ⎪⎩2md+12−2m−1,d odd,(m+1)md2−2m−1,d even.

## References

• [1] Dankelmann, P. (2011) On the distance distribution of trees. Discrete Appl. Math., 159, pp. 945–952.
• [2] De Jong, J. V., MacLeod, J. C., and Steel, M. (2015) Neighborhoods of Phylogenetic Trees: Exact and Asymptotic Counts. SIAM J. Discr