The Maximum Number of Squares in a Tree

The Maximum Number of Squares
in a Tree
Maxime Crochemore, Costas Iliopoulos,
Tomasz Kociumaka, Marcin Kubica,
Jakub Radoszewski, Wojciech Rytter,
Tomasz Waleń, Wojciech Tyczyński
King’s College London, University of Warsaw
CPM 2012
Helsinki, July 3, 2012
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
1/15
Square
a b b b a b b b
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
2/15
Square in a word
b
a
b
a b b b a b b b
Tomasz Kociumaka
a
a
The Maximum Number of Squares in a Tree
b
2/15
Square in a tree
b
a
b
a b b b a b b b
Tomasz Kociumaka
a
a
The Maximum Number of Squares in a Tree
b
2/15
Square in a tree
a
b
b
b
b
a
b
a
a
a
a
b ba
a
b
a
b
b
a
a
ba
b
a
b
a
a
b
a
a
ba
Tomasz Kociumaka
b
b
b
a
a
a bb b b aa b b b
b
b
a
b
a
a bb
a
b
a
a
a
The Maximum Number of Squares in a Tree
2/15
Square in a tree
a
b
b
b
b
a
b
a
a
a
a
b ba
a
b
a
b
b
a
a
ba
b
a
b
a
a
b
a
a
ba
Tomasz Kociumaka
b
b
b
a
a
a bb b b aa b b b
b
b
a
b
a
a bb
a
b
a
a
a
The Maximum Number of Squares in a Tree
2/15
Number of squares in a tree
We consider unrooted, unoriented trees with edges
labeled by single letters. Subword of such a tree is a
value of a simple path.
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
3/15
Number of squares in a tree
We consider unrooted, unoriented trees with edges
labeled by single letters. Subword of such a tree is a
value of a simple path.
a
T :
c
a
b
Tomasz Kociumaka
b
b
a
b
b
a
c
The Maximum Number of Squares in a Tree
3/15
Number of squares in a tree
We consider unrooted, unoriented trees with edges
labeled by single letters. Subword of such a tree is a
value of a simple path.
a
T :
c
a
b
b
b
a
b
b
a
c
Squares in T : aa
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
3/15
Number of squares in a tree
We consider unrooted, unoriented trees with edges
labeled by single letters. Subword of such a tree is a
value of a simple path.
a
T :
c
a
b
b
b
a
b
b
a
c
Squares in T : aa
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
3/15
Number of squares in a tree
We consider unrooted, unoriented trees with edges
labeled by single letters. Subword of such a tree is a
value of a simple path.
a
T :
c
a
b
b
b
a
b
b
a
c
Squares in T : aa, abaaba
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
3/15
Number of squares in a tree
We consider unrooted, unoriented trees with edges
labeled by single letters. Subword of such a tree is a
value of a simple path.
a
T :
c
a
b
b
b
a
b
b
a
c
Squares in T : aa, abaaba
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
3/15
Number of squares in a tree
We consider unrooted, unoriented trees with edges
labeled by single letters. Subword of such a tree is a
value of a simple path.
a
T :
c
a
b
b
b
a
b
b
a
c
Squares in T : aa, abaaba, bb
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
3/15
Number of squares in a tree
We consider unrooted, unoriented trees with edges
labeled by single letters. Subword of such a tree is a
value of a simple path.
a
T :
c
a
b
b
b
a
b
b
a
c
Squares in T : aa, abaaba, bb
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
3/15
Number of squares in a tree
We consider unrooted, unoriented trees with edges
labeled by single letters. Subword of such a tree is a
value of a simple path.
a
T :
c
a
b
b
b
a
b
b
a
c
Squares in T : aa, abaaba, bb
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
3/15
Number of squares in a tree
We consider unrooted, unoriented trees with edges
labeled by single letters. Subword of such a tree is a
value of a simple path.
a
T :
c
a
b
b
b
a
b
b
a
c
Squares in T : aa, abaaba, bb
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
3/15
Number of squares in a tree
We consider unrooted, unoriented trees with edges
labeled by single letters. Subword of such a tree is a
value of a simple path.
a
T :
c
a
b
b
b
a
b
b
a
c
Squares in T : aa, abaaba, bb, bcbc
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
3/15
Number of squares in a tree
We consider unrooted, unoriented trees with edges
labeled by single letters. Subword of such a tree is a
value of a simple path.
a
T :
c
a
b
b
b
a
b
b
a
c
Squares in T : aa, abaaba, bb, bcbc, cbcb
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
3/15
Number of squares in a tree
We consider unrooted, unoriented trees with edges
labeled by single letters. Subword of such a tree is a
value of a simple path.
a
T :
c
a
b
b
b
a
b
b
a
c
Squares in T : aa, abaaba, bb, bcbc, cbcb.
There are 5 distinct squares, i.e. sq(T ) = 5.
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
3/15
Maximum number of squares
What is the maximum number of squares a tree of
n nodes might contain?
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
4/15
Maximum number of squares
What is the maximum number of squares a tree of
n nodes might contain?
Theorem (This paper)
A tree of n nodes contains O(n4/3 ) squares.
This bound is asymptotically tight.
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
4/15
Maximum number of squares
What is the maximum number of squares a tree of
n nodes might contain?
Theorem (This paper)
A tree of n nodes contains O(n4/3 ) squares.
This bound is asymptotically tight.
Theorem (Fraenkel & Simpson, 1998)
A word of length n contains at most 2n squares.
There is a word of length n with n − o(n) squares.
Conjecture
A word of length n contains at most n squares.
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
4/15
Comb
branches
spine
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
5/15
Standard comb
a
a
a
b
b
a
a
a
a
a
a
a
a
a
a
a
b
b
b
b
a
Tomasz Kociumaka
a
a
a
a
a
The Maximum Number of Squares in a Tree
5/15
Lower bound
a a a
a a a
m2 .. .. ..
. . .
a a a
b b b
···
a a
m
a a
a a
.. ..
. .
a
a
..
.
a
a
..
.
a
a
..
.
a a
a
a
a
b b
· · · a ba · · · ba a · · · a b
a a a
m
m
2
m
Branches at {0, 1, 2, . . . , m − 1, m, 2m, 3m, . . . , m2 }.
Θ(m3 ) nodes,
Θ(m4 ) squares: {ai bai+j baj : 1 ≤ i + j ≤ m2 }.
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
6/15
Lower bound
a a a
a a a
m2 .. .. ..
. . .
a a a
b b b
···
a a
m
a a
a a
.. ..
. .
a
a
..
.
a
a
..
.
a
a
..
.
a a
a
a
a
b b
· · · a ba · · · ba a · · · a b
a a a
m
m
2
m
Branches at {0, 1, 2, . . . , m − 1, m, 2m, 3m, . . . , m2 }.
Θ(m3 ) nodes,
Θ(m4 ) squares: {ai bai+j baj : 1 ≤ i + j ≤ m2 }.
Theorem
There are trees of n nodes with Θ(n4/3 ) squares.
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
6/15
Centroid decomposition of T
T1
Tk
..
.
R
T4
Tomasz Kociumaka
T2
|Ti | ≤
|T |
2
T3
The Maximum Number of Squares in a Tree
7/15
Centroid decomposition of T
T1
Tk
..
.
R
T4
T2
|Ti | ≤
|T |
2
T3
sq(T , R) – number of squares passing through R
sq(T ) ≤ sq(T , R) + Σi sq(Ti )
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
7/15
Centroid decomposition of T
T1
Tk
..
.
R
T4
T2
|Ti | ≤
|T |
2
T3
sq(T , R) – number of squares passing through R
sq(T ) ≤ sq(T , R) + Σi sq(Ti )
Fact
If sq(T , R) = O(n4/3 ) for every tree T of size n,
then sq(T ) = O(n4/3 ) for every tree T of size n.
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
7/15
D-trees — deterministic double trees
R
a
a
a
a
a
b b
a
b
b
a
b
a
a
c
Tree
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
8/15
D-trees — deterministic double trees
a
a
a
a
b b
a
b
a
a
a
b b
a
a
b
a
b
R
a
a
c
b
a
R
a
a
b
a
b
a
b
a
a
Tree
c
a
a
a
a
b b
b
a
b
a
a
c
Double tree
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
8/15
D-trees — deterministic double trees
a
a
a
a
b b
a
b
a
a
a
b b
a
a
a
b
a
b
a
b
a
a
Tree
c
a
a
a
a
b b
a
b
a
b
a
b
b
a
b
a
b
a
a
c
Double tree
Tomasz Kociumaka
b c
R
a
b
a
a
R
a
a
c
b
a
R
a
a
a
b
b
a
b
a
b c
D-tree
The Maximum Number of Squares in a Tree
8/15
Squares in D-trees
Tu
R
Tl
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
9/15
Squares in D-trees
Tu
R
Tl
The following lemma implies the main theorem:
Lemma
For any D-tree of size n the number of squares with
midpoint in Tl and ending in Tu is O(n4/3 ).
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
9/15
Squares in D-trees
The following lemma implies the main theorem:
Lemma
For any D-tree of size n the number of squares with
midpoint in Tl and ending in Tu is O(n4/3 ).
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
9/15
Squares in D-trees
border
border
The following lemma implies the main theorem:
Lemma
For any D-tree of size n the number of squares with
midpoint in Tl and ending in Tu is O(n4/3 ).
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
9/15
Types of borders
Definition
We say that u is of periodic type (p, q) if
u = (pq)k p for k ≥ 2, q 6= ε, and pq is primitive.
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
10/15
Types of borders
Definition
We say that u is of periodic type (p, q) if
u = (pq)k p for k ≥ 2, q 6= ε, and pq is primitive.
Let w be a word of length ≤ n.
O(log n) borders of w have no periodic type.
Remaining borders are of O(log n) types.
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
10/15
Types of borders
Definition
We say that u is of periodic type (p, q) if
u = (pq)k p for k ≥ 2, q 6= ε, and pq is primitive.
Let w be a word of length ≤ n.
O(log n) borders of w have no periodic type.
Remaining borders are of O(log n) types.
If w has borders of periodic type (p, q) then it has
the following representation:
w = (pq)k p (global borders) or
w = (pq)l pyp(qp)r (regular borders).
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
10/15
Squares and borders
Global borders – easy, O(n) in total.
Regular boders of a single type:
p q p q p q p
v
y
p q p q p q p
R
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
11/15
Squares and borders
Global borders – easy, O(n) in total.
Regular boders of a single type:
(pqpqpqpy )
2
p q p q p q p
v
y
p q p q p q p y
R
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
11/15
Squares and borders
Global borders – easy, O(n) in total.
Regular boders of a single type:
q
p
q
p
2
(pqpqpqpypqpq)
p q p q p q p
v
y
y
p q p q p q p y
Rq p q p
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
11/15
Squares and borders
Global borders – easy, O(n) in total.
Regular boders of a single type:
q
p
q
p
2
(pqpqpqpypqpqpq)
p q p q p q p
v
y
q
p
q
p
q
p
y
y
p q p q p q p y
Rq p q p q p
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
11/15
General combs
A (p, q, y )-comb of T is the maximal common
subtree of T and the following infinite D-tree:
q
p
q
p
q
p
q
p
q
p
q
p
q
p
q
p
q
p
q
p
q
p
q
p
y
y
y
y
y
p q p q p q p q p q p y
q
p
q
p
q
p
q
p
q
p
y
y
y
y
y
y R
p
q
p
q
p
p
q
p
q
p
p
q
p
q
p
p
q
p
q
p
p
q
p
q
p
p
q
p
q
p
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
12/15
Squares induced by combs
q
p
q
p
y
p q p q p q p y
q
p
q p q p
y
y
y R
p
p p
q
q q
p
p p
q
q q
p
p p
q
q
p
p
q
p
y
q p q p
q
p
q
p
y
The blue nodes are called main nodes of a comb.
Squares with both endpoints at these nodes are
induced by a comb.
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
13/15
Squares induced by combs
q
p
q
p
y
p q p q p q p y
q
p
q p q p
y
y
y R
p
p p
q
q q
p
p p
q
q q
p
p p
q
q
p
p
q
p
y
q p q p
q
p
q
p
y
The blue nodes are called main nodes of a comb.
Squares with both endpoints at these nodes are
induced by a comb.
Size of a comb is the number of main nodes.
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
13/15
Outline of the central proof
1
2
Just O(n log n) squares are not induced by
combs.
Small combs (≤ n0.6 ) induce o(n4/3 ) squares:
a comb of size k induces O(k 1/2 ) squares starting
in a single main node,
a single node in Tl can be a main node of O(log n)
combs.
3
Big combs (> n0.6 ) induce O(n4/3 ) squares:
combs are almost disjoint in a certain sense:
|Main(C) ∩ Main(C 0 )| ≤ 4,
the total size of big combs is O(n),
a comb of size k induces O(k 4/3 ) squares.
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
14/15
Thank you
Thank you for your attention!
Tomasz Kociumaka
The Maximum Number of Squares in a Tree
15/15