Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to...
Transcript of Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to...
![Page 1: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/1.jpg)
Counting Trees
Counting Trees
Michael L. Littman
CS 22 2020
April 27, 2020
1 / 112
![Page 2: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/2.jpg)
Counting Trees
Overview
Puzzle
Attempt 1: Choosing edges
Attempt 2: Building up
Attempt 3
Prufer codes
2 / 112
![Page 3: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/3.jpg)
Counting Trees
Puzzle
Format
Different format today.
We’re going to look at one problem andwe’ll see my failed attempts to solve it, along with a solution thatactually works.
3 / 112
![Page 4: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/4.jpg)
Counting Trees
Puzzle
Format
Different format today. We’re going to look at one problem andwe’ll see my failed attempts to solve it, along with a solution thatactually works.
4 / 112
![Page 5: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/5.jpg)
Counting Trees
Puzzle
Counting trees
How many ways can we connected n vertices together into a tree?
Trees on 2 and trees on 3:
5 / 112
![Page 6: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/6.jpg)
Counting Trees
Puzzle
Counting trees
How many ways can we connected n vertices together into a tree?
Trees on 2 and trees on 3:
6 / 112
![Page 7: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/7.jpg)
Counting Trees
Puzzle
Counting trees
How many ways can we connected n vertices together into a tree?
Trees on 2 and trees on 3:
7 / 112
![Page 8: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/8.jpg)
Counting Trees
Puzzle
Trees on 4
8 / 112
![Page 9: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/9.jpg)
Counting Trees
Puzzle
What we know so far
Trees: Connected, acyclic.
n trees
2 13 34 16
9 / 112
![Page 10: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/10.jpg)
Counting Trees
Puzzle
What we know so far
Trees: Connected, acyclic.
n trees
2 13 34 16
10 / 112
![Page 11: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/11.jpg)
Counting Trees
Attempt 1: Choosing edges
Choosing edges
Ok, first thought.
A tree on n vertices has n − 1 edges out of allpossible edges:
( (n2
)n − 1
).
n trees
2 13 34 20 > 16
We counted cycles that aren’t trees.
11 / 112
![Page 12: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/12.jpg)
Counting Trees
Attempt 1: Choosing edges
Choosing edges
Ok, first thought. A tree on n vertices has n − 1 edges
out of allpossible edges:
( (n2
)n − 1
).
n trees
2 13 34 20 > 16
We counted cycles that aren’t trees.
12 / 112
![Page 13: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/13.jpg)
Counting Trees
Attempt 1: Choosing edges
Choosing edges
Ok, first thought. A tree on n vertices has n − 1 edges out of allpossible edges:
( (n2
)n − 1
).
n trees
2 13 34 20 > 16
We counted cycles that aren’t trees.
13 / 112
![Page 14: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/14.jpg)
Counting Trees
Attempt 1: Choosing edges
Choosing edges
Ok, first thought. A tree on n vertices has n − 1 edges out of allpossible edges:
( (n2
)n − 1
).
n trees
2 13 34 20 > 16
We counted cycles that aren’t trees.
14 / 112
![Page 15: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/15.jpg)
Counting Trees
Attempt 1: Choosing edges
Choosing edges
Ok, first thought. A tree on n vertices has n − 1 edges out of allpossible edges:
( (n2
)n − 1
).
n trees
2 13 34 20
> 16
We counted cycles that aren’t trees.
15 / 112
![Page 16: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/16.jpg)
Counting Trees
Attempt 1: Choosing edges
Choosing edges
Ok, first thought. A tree on n vertices has n − 1 edges out of allpossible edges:
( (n2
)n − 1
).
n trees
2 13 34 20 > 16
We counted cycles that aren’t trees.
16 / 112
![Page 17: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/17.jpg)
Counting Trees
Attempt 1: Choosing edges
Choosing edges
Ok, first thought. A tree on n vertices has n − 1 edges out of allpossible edges:
( (n2
)n − 1
).
n trees
2 13 34 20 > 16
We counted cycles that aren’t trees.
17 / 112
![Page 18: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/18.jpg)
Counting Trees
Attempt 2: Building up
Ways to add a vertex
So, let’s be careful to only generate trees.
Here’s the thought.Consider a tree on n vertices. We can add vertex n + 1 andconnect it into the tree n different ways.
So, 2 vertices make 1 tree. Adding the 3rd vertex creates 2 timesmore. Adding the 4th vertex creates 3 times more.
Generalizing, we get (n − 1)! trees.
n trees
2 13 2 < 34 6 < 16
Now, we’re only counting trees, but we’re missing some trees. Inparticular, we’re missing trees where the last vertex is somewherein the middle.
18 / 112
![Page 19: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/19.jpg)
Counting Trees
Attempt 2: Building up
Ways to add a vertex
So, let’s be careful to only generate trees. Here’s the thought.
Consider a tree on n vertices. We can add vertex n + 1 andconnect it into the tree n different ways.
So, 2 vertices make 1 tree. Adding the 3rd vertex creates 2 timesmore. Adding the 4th vertex creates 3 times more.
Generalizing, we get (n − 1)! trees.
n trees
2 13 2 < 34 6 < 16
Now, we’re only counting trees, but we’re missing some trees. Inparticular, we’re missing trees where the last vertex is somewherein the middle.
19 / 112
![Page 20: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/20.jpg)
Counting Trees
Attempt 2: Building up
Ways to add a vertex
So, let’s be careful to only generate trees. Here’s the thought.Consider a tree on n vertices.
We can add vertex n + 1 andconnect it into the tree n different ways.
So, 2 vertices make 1 tree. Adding the 3rd vertex creates 2 timesmore. Adding the 4th vertex creates 3 times more.
Generalizing, we get (n − 1)! trees.
n trees
2 13 2 < 34 6 < 16
Now, we’re only counting trees, but we’re missing some trees. Inparticular, we’re missing trees where the last vertex is somewherein the middle.
20 / 112
![Page 21: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/21.jpg)
Counting Trees
Attempt 2: Building up
Ways to add a vertex
So, let’s be careful to only generate trees. Here’s the thought.Consider a tree on n vertices. We can add vertex n + 1 andconnect it into the tree n different ways.
So, 2 vertices make 1 tree. Adding the 3rd vertex creates 2 timesmore. Adding the 4th vertex creates 3 times more.
Generalizing, we get (n − 1)! trees.
n trees
2 13 2 < 34 6 < 16
Now, we’re only counting trees, but we’re missing some trees. Inparticular, we’re missing trees where the last vertex is somewherein the middle.
21 / 112
![Page 22: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/22.jpg)
Counting Trees
Attempt 2: Building up
Ways to add a vertex
So, let’s be careful to only generate trees. Here’s the thought.Consider a tree on n vertices. We can add vertex n + 1 andconnect it into the tree n different ways.
So, 2 vertices make 1 tree.
Adding the 3rd vertex creates 2 timesmore. Adding the 4th vertex creates 3 times more.
Generalizing, we get (n − 1)! trees.
n trees
2 13 2 < 34 6 < 16
Now, we’re only counting trees, but we’re missing some trees. Inparticular, we’re missing trees where the last vertex is somewherein the middle.
22 / 112
![Page 23: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/23.jpg)
Counting Trees
Attempt 2: Building up
Ways to add a vertex
So, let’s be careful to only generate trees. Here’s the thought.Consider a tree on n vertices. We can add vertex n + 1 andconnect it into the tree n different ways.
So, 2 vertices make 1 tree. Adding the 3rd vertex creates 2 timesmore.
Adding the 4th vertex creates 3 times more.
Generalizing, we get (n − 1)! trees.
n trees
2 13 2 < 34 6 < 16
Now, we’re only counting trees, but we’re missing some trees. Inparticular, we’re missing trees where the last vertex is somewherein the middle.
23 / 112
![Page 24: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/24.jpg)
Counting Trees
Attempt 2: Building up
Ways to add a vertex
So, let’s be careful to only generate trees. Here’s the thought.Consider a tree on n vertices. We can add vertex n + 1 andconnect it into the tree n different ways.
So, 2 vertices make 1 tree. Adding the 3rd vertex creates 2 timesmore. Adding the 4th vertex creates 3 times more.
Generalizing, we get (n − 1)! trees.
n trees
2 13 2 < 34 6 < 16
Now, we’re only counting trees, but we’re missing some trees. Inparticular, we’re missing trees where the last vertex is somewherein the middle.
24 / 112
![Page 25: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/25.jpg)
Counting Trees
Attempt 2: Building up
Ways to add a vertex
So, let’s be careful to only generate trees. Here’s the thought.Consider a tree on n vertices. We can add vertex n + 1 andconnect it into the tree n different ways.
So, 2 vertices make 1 tree. Adding the 3rd vertex creates 2 timesmore. Adding the 4th vertex creates 3 times more.
Generalizing, we get (n − 1)! trees.
n trees
2 13 2 < 34 6 < 16
Now, we’re only counting trees, but we’re missing some trees. Inparticular, we’re missing trees where the last vertex is somewherein the middle.
25 / 112
![Page 26: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/26.jpg)
Counting Trees
Attempt 2: Building up
Ways to add a vertex
So, let’s be careful to only generate trees. Here’s the thought.Consider a tree on n vertices. We can add vertex n + 1 andconnect it into the tree n different ways.
So, 2 vertices make 1 tree. Adding the 3rd vertex creates 2 timesmore. Adding the 4th vertex creates 3 times more.
Generalizing, we get (n − 1)! trees.
n trees
2 13 2
< 34 6 < 16
Now, we’re only counting trees, but we’re missing some trees. Inparticular, we’re missing trees where the last vertex is somewherein the middle.
26 / 112
![Page 27: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/27.jpg)
Counting Trees
Attempt 2: Building up
Ways to add a vertex
So, let’s be careful to only generate trees. Here’s the thought.Consider a tree on n vertices. We can add vertex n + 1 andconnect it into the tree n different ways.
So, 2 vertices make 1 tree. Adding the 3rd vertex creates 2 timesmore. Adding the 4th vertex creates 3 times more.
Generalizing, we get (n − 1)! trees.
n trees
2 13 2 < 34 6
< 16
Now, we’re only counting trees, but we’re missing some trees. Inparticular, we’re missing trees where the last vertex is somewherein the middle.
27 / 112
![Page 28: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/28.jpg)
Counting Trees
Attempt 2: Building up
Ways to add a vertex
So, let’s be careful to only generate trees. Here’s the thought.Consider a tree on n vertices. We can add vertex n + 1 andconnect it into the tree n different ways.
So, 2 vertices make 1 tree. Adding the 3rd vertex creates 2 timesmore. Adding the 4th vertex creates 3 times more.
Generalizing, we get (n − 1)! trees.
n trees
2 13 2 < 34 6 < 16
Now, we’re only counting trees, but we’re missing some trees. Inparticular, we’re missing trees where the last vertex is somewherein the middle.
28 / 112
![Page 29: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/29.jpg)
Counting Trees
Attempt 2: Building up
Ways to add a vertex
So, let’s be careful to only generate trees. Here’s the thought.Consider a tree on n vertices. We can add vertex n + 1 andconnect it into the tree n different ways.
So, 2 vertices make 1 tree. Adding the 3rd vertex creates 2 timesmore. Adding the 4th vertex creates 3 times more.
Generalizing, we get (n − 1)! trees.
n trees
2 13 2 < 34 6 < 16
Now, we’re only counting trees, but we’re missing some trees.
Inparticular, we’re missing trees where the last vertex is somewherein the middle.
29 / 112
![Page 30: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/30.jpg)
Counting Trees
Attempt 2: Building up
Ways to add a vertex
So, let’s be careful to only generate trees. Here’s the thought.Consider a tree on n vertices. We can add vertex n + 1 andconnect it into the tree n different ways.
So, 2 vertices make 1 tree. Adding the 3rd vertex creates 2 timesmore. Adding the 4th vertex creates 3 times more.
Generalizing, we get (n − 1)! trees.
n trees
2 13 2 < 34 6 < 16
Now, we’re only counting trees, but we’re missing some trees. Inparticular, we’re missing trees where the last vertex is somewherein the middle.
30 / 112
![Page 31: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/31.jpg)
Counting Trees
Attempt 2: Building up
Generated 4 trees
31 / 112
![Page 32: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/32.jpg)
Counting Trees
Attempt 3
More careful growing
When we add in vertex n + 1, the other n nodes might not be atree.
They might be a forest. In general, vertex n + 1 will have oneedge to each connected component in the forest. For the edge toconnected component i , it will have a choice of which of thevertices in the connected component to connect to.
I worked on this path for awhile, and could almost write down anexpression, but it was complicated and I didn’t think I couldsimplify it. The basic idea is consider all the ways of making a treewith n′ nodes for all n′ ≤ n, then all the ways n nodes can bepartitioned into clusters, then sum and multiply...
But, even the question of how many partitions there are for nitems is hairy. See: https://oeis.org/A000110 .
32 / 112
![Page 33: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/33.jpg)
Counting Trees
Attempt 3
More careful growing
When we add in vertex n + 1, the other n nodes might not be atree. They might be a forest.
In general, vertex n + 1 will have oneedge to each connected component in the forest. For the edge toconnected component i , it will have a choice of which of thevertices in the connected component to connect to.
I worked on this path for awhile, and could almost write down anexpression, but it was complicated and I didn’t think I couldsimplify it. The basic idea is consider all the ways of making a treewith n′ nodes for all n′ ≤ n, then all the ways n nodes can bepartitioned into clusters, then sum and multiply...
But, even the question of how many partitions there are for nitems is hairy. See: https://oeis.org/A000110 .
33 / 112
![Page 34: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/34.jpg)
Counting Trees
Attempt 3
More careful growing
When we add in vertex n + 1, the other n nodes might not be atree. They might be a forest. In general, vertex n + 1 will have oneedge to each connected component in the forest.
For the edge toconnected component i , it will have a choice of which of thevertices in the connected component to connect to.
I worked on this path for awhile, and could almost write down anexpression, but it was complicated and I didn’t think I couldsimplify it. The basic idea is consider all the ways of making a treewith n′ nodes for all n′ ≤ n, then all the ways n nodes can bepartitioned into clusters, then sum and multiply...
But, even the question of how many partitions there are for nitems is hairy. See: https://oeis.org/A000110 .
34 / 112
![Page 35: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/35.jpg)
Counting Trees
Attempt 3
More careful growing
When we add in vertex n + 1, the other n nodes might not be atree. They might be a forest. In general, vertex n + 1 will have oneedge to each connected component in the forest. For the edge toconnected component i , it will have a choice of which of thevertices in the connected component to connect to.
I worked on this path for awhile, and could almost write down anexpression, but it was complicated and I didn’t think I couldsimplify it. The basic idea is consider all the ways of making a treewith n′ nodes for all n′ ≤ n, then all the ways n nodes can bepartitioned into clusters, then sum and multiply...
But, even the question of how many partitions there are for nitems is hairy. See: https://oeis.org/A000110 .
35 / 112
![Page 36: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/36.jpg)
Counting Trees
Attempt 3
More careful growing
When we add in vertex n + 1, the other n nodes might not be atree. They might be a forest. In general, vertex n + 1 will have oneedge to each connected component in the forest. For the edge toconnected component i , it will have a choice of which of thevertices in the connected component to connect to.
I worked on this path for awhile, and could almost write down anexpression, but it was complicated and I didn’t think I couldsimplify it.
The basic idea is consider all the ways of making a treewith n′ nodes for all n′ ≤ n, then all the ways n nodes can bepartitioned into clusters, then sum and multiply...
But, even the question of how many partitions there are for nitems is hairy. See: https://oeis.org/A000110 .
36 / 112
![Page 37: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/37.jpg)
Counting Trees
Attempt 3
More careful growing
When we add in vertex n + 1, the other n nodes might not be atree. They might be a forest. In general, vertex n + 1 will have oneedge to each connected component in the forest. For the edge toconnected component i , it will have a choice of which of thevertices in the connected component to connect to.
I worked on this path for awhile, and could almost write down anexpression, but it was complicated and I didn’t think I couldsimplify it. The basic idea is consider all the ways of making a treewith n′ nodes for all n′ ≤ n, then all the ways n nodes can bepartitioned into clusters, then sum and multiply...
But, even the question of how many partitions there are for nitems is hairy. See: https://oeis.org/A000110 .
37 / 112
![Page 38: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/38.jpg)
Counting Trees
Attempt 3
More careful growing
When we add in vertex n + 1, the other n nodes might not be atree. They might be a forest. In general, vertex n + 1 will have oneedge to each connected component in the forest. For the edge toconnected component i , it will have a choice of which of thevertices in the connected component to connect to.
I worked on this path for awhile, and could almost write down anexpression, but it was complicated and I didn’t think I couldsimplify it. The basic idea is consider all the ways of making a treewith n′ nodes for all n′ ≤ n, then all the ways n nodes can bepartitioned into clusters, then sum and multiply...
But, even the question of how many partitions there are for nitems is hairy.
See: https://oeis.org/A000110 .
38 / 112
![Page 39: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/39.jpg)
Counting Trees
Attempt 3
More careful growing
When we add in vertex n + 1, the other n nodes might not be atree. They might be a forest. In general, vertex n + 1 will have oneedge to each connected component in the forest. For the edge toconnected component i , it will have a choice of which of thevertices in the connected component to connect to.
I worked on this path for awhile, and could almost write down anexpression, but it was complicated and I didn’t think I couldsimplify it. The basic idea is consider all the ways of making a treewith n′ nodes for all n′ ≤ n, then all the ways n nodes can bepartitioned into clusters, then sum and multiply...
But, even the question of how many partitions there are for nitems is hairy. See: https://oeis.org/A000110 .
39 / 112
![Page 40: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/40.jpg)
Counting Trees
Prufer codes
Better way to look at it
Sometimes there’s just a better way to look at it.
It’s definitely notobvious (to me!). But, it’s clever and gives a nice clean answer.
1. Create a “normal form” for trees. That way, we can at leastnotice when two different trees are actually the same.
2. Find a compact encoding for these trees. Here, “compact”means no extraneous information.
3. Then, we can show we have a bijection (!) between trees andthe encoding.
4. If we’re lucky, it’ll be easier to count encodings than trees.
40 / 112
![Page 41: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/41.jpg)
Counting Trees
Prufer codes
Better way to look at it
Sometimes there’s just a better way to look at it. It’s definitely notobvious (to me!).
But, it’s clever and gives a nice clean answer.
1. Create a “normal form” for trees. That way, we can at leastnotice when two different trees are actually the same.
2. Find a compact encoding for these trees. Here, “compact”means no extraneous information.
3. Then, we can show we have a bijection (!) between trees andthe encoding.
4. If we’re lucky, it’ll be easier to count encodings than trees.
41 / 112
![Page 42: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/42.jpg)
Counting Trees
Prufer codes
Better way to look at it
Sometimes there’s just a better way to look at it. It’s definitely notobvious (to me!). But, it’s clever and gives a nice clean answer.
1. Create a “normal form” for trees. That way, we can at leastnotice when two different trees are actually the same.
2. Find a compact encoding for these trees. Here, “compact”means no extraneous information.
3. Then, we can show we have a bijection (!) between trees andthe encoding.
4. If we’re lucky, it’ll be easier to count encodings than trees.
42 / 112
![Page 43: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/43.jpg)
Counting Trees
Prufer codes
Better way to look at it
Sometimes there’s just a better way to look at it. It’s definitely notobvious (to me!). But, it’s clever and gives a nice clean answer.
1. Create a “normal form” for trees.
That way, we can at leastnotice when two different trees are actually the same.
2. Find a compact encoding for these trees. Here, “compact”means no extraneous information.
3. Then, we can show we have a bijection (!) between trees andthe encoding.
4. If we’re lucky, it’ll be easier to count encodings than trees.
43 / 112
![Page 44: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/44.jpg)
Counting Trees
Prufer codes
Better way to look at it
Sometimes there’s just a better way to look at it. It’s definitely notobvious (to me!). But, it’s clever and gives a nice clean answer.
1. Create a “normal form” for trees. That way, we can at leastnotice when two different trees are actually the same.
2. Find a compact encoding for these trees. Here, “compact”means no extraneous information.
3. Then, we can show we have a bijection (!) between trees andthe encoding.
4. If we’re lucky, it’ll be easier to count encodings than trees.
44 / 112
![Page 45: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/45.jpg)
Counting Trees
Prufer codes
Better way to look at it
Sometimes there’s just a better way to look at it. It’s definitely notobvious (to me!). But, it’s clever and gives a nice clean answer.
1. Create a “normal form” for trees. That way, we can at leastnotice when two different trees are actually the same.
2. Find a compact encoding for these trees.
Here, “compact”means no extraneous information.
3. Then, we can show we have a bijection (!) between trees andthe encoding.
4. If we’re lucky, it’ll be easier to count encodings than trees.
45 / 112
![Page 46: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/46.jpg)
Counting Trees
Prufer codes
Better way to look at it
Sometimes there’s just a better way to look at it. It’s definitely notobvious (to me!). But, it’s clever and gives a nice clean answer.
1. Create a “normal form” for trees. That way, we can at leastnotice when two different trees are actually the same.
2. Find a compact encoding for these trees. Here, “compact”means no extraneous information.
3. Then, we can show we have a bijection (!) between trees andthe encoding.
4. If we’re lucky, it’ll be easier to count encodings than trees.
46 / 112
![Page 47: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/47.jpg)
Counting Trees
Prufer codes
Better way to look at it
Sometimes there’s just a better way to look at it. It’s definitely notobvious (to me!). But, it’s clever and gives a nice clean answer.
1. Create a “normal form” for trees. That way, we can at leastnotice when two different trees are actually the same.
2. Find a compact encoding for these trees. Here, “compact”means no extraneous information.
3. Then, we can show we have a bijection (!) between trees andthe encoding.
4. If we’re lucky, it’ll be easier to count encodings than trees.
47 / 112
![Page 48: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/48.jpg)
Counting Trees
Prufer codes
Better way to look at it
Sometimes there’s just a better way to look at it. It’s definitely notobvious (to me!). But, it’s clever and gives a nice clean answer.
1. Create a “normal form” for trees. That way, we can at leastnotice when two different trees are actually the same.
2. Find a compact encoding for these trees. Here, “compact”means no extraneous information.
3. Then, we can show we have a bijection (!) between trees andthe encoding.
4. If we’re lucky, it’ll be easier to count encodings than trees.
48 / 112
![Page 49: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/49.jpg)
Counting Trees
Prufer codes
Normal form for trees
Choose node n to be the root.
Order children smallest (left) tobiggest (right). There are no other choices.
49 / 112
![Page 50: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/50.jpg)
Counting Trees
Prufer codes
Normal form for trees
Choose node n to be the root. Order children smallest (left) tobiggest (right).
There are no other choices.
50 / 112
![Page 51: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/51.jpg)
Counting Trees
Prufer codes
Normal form for trees
Choose node n to be the root. Order children smallest (left) tobiggest (right). There are no other choices.
51 / 112
![Page 52: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/52.jpg)
Counting Trees
Prufer codes
Normal form for trees
Choose node n to be the root. Order children smallest (left) tobiggest (right). There are no other choices.
52 / 112
![Page 53: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/53.jpg)
Counting Trees
Prufer codes
Normal form for trees
Choose node n to be the root. Order children smallest (left) tobiggest (right). There are no other choices.
53 / 112
![Page 54: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/54.jpg)
Counting Trees
Prufer codes
Encoding a tree
Every node has a unique parent.
So, we code just give the parentfor each node: 3 7 4 5 11 3 10 2 10 4.
List n − 1 numbers, each with a choice of n − 1 numbers (can’tpick yourself!). That’s (n − 1)n−1.
Anything extraneous? Yes, can encode a loop: 3 1 2 5.
54 / 112
![Page 55: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/55.jpg)
Counting Trees
Prufer codes
Encoding a tree
Every node has a unique parent. So, we code just give the parentfor each node: 3 7 4 5 11 3 10 2 10 4.
List n − 1 numbers, each with a choice of n − 1 numbers (can’tpick yourself!).
That’s (n − 1)n−1.
Anything extraneous? Yes, can encode a loop: 3 1 2 5.
55 / 112
![Page 56: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/56.jpg)
Counting Trees
Prufer codes
Encoding a tree
Every node has a unique parent. So, we code just give the parentfor each node: 3 7 4 5 11 3 10 2 10 4.
List n − 1 numbers, each with a choice of n − 1 numbers (can’tpick yourself!). That’s (n − 1)n−1.
Anything extraneous? Yes, can encode a loop: 3 1 2 5.
56 / 112
![Page 57: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/57.jpg)
Counting Trees
Prufer codes
Encoding a tree
Every node has a unique parent. So, we code just give the parentfor each node: 3 7 4 5 11 3 10 2 10 4.
List n − 1 numbers, each with a choice of n − 1 numbers (can’tpick yourself!). That’s (n − 1)n−1.
Anything extraneous?
Yes, can encode a loop: 3 1 2 5.
57 / 112
![Page 58: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/58.jpg)
Counting Trees
Prufer codes
Encoding a tree
Every node has a unique parent. So, we code just give the parentfor each node: 3 7 4 5 11 3 10 2 10 4.
List n − 1 numbers, each with a choice of n − 1 numbers (can’tpick yourself!). That’s (n − 1)n−1.
Anything extraneous? Yes, can encode a loop:
3 1 2 5.
58 / 112
![Page 59: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/59.jpg)
Counting Trees
Prufer codes
Encoding a tree
Every node has a unique parent. So, we code just give the parentfor each node: 3 7 4 5 11 3 10 2 10 4.
List n − 1 numbers, each with a choice of n − 1 numbers (can’tpick yourself!). That’s (n − 1)n−1.
Anything extraneous? Yes, can encode a loop: 3 1 2 5.
59 / 112
![Page 60: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/60.jpg)
Counting Trees
Prufer codes
Sanity check
Could it be (n − 1)n−1?
n trees
2 13 4 > 34 27 > 16
Yeah, we’re definitely overcounting. But, we’re guaranteed not toundercount. Every tree has a representation in this scheme. But,some representations do not produce trees. It’s not a bijection.
60 / 112
![Page 61: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/61.jpg)
Counting Trees
Prufer codes
Sanity check
Could it be (n − 1)n−1?
n trees
2 13 4
> 34 27 > 16
Yeah, we’re definitely overcounting. But, we’re guaranteed not toundercount. Every tree has a representation in this scheme. But,some representations do not produce trees. It’s not a bijection.
61 / 112
![Page 62: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/62.jpg)
Counting Trees
Prufer codes
Sanity check
Could it be (n − 1)n−1?
n trees
2 13 4 > 34 27
> 16
Yeah, we’re definitely overcounting. But, we’re guaranteed not toundercount. Every tree has a representation in this scheme. But,some representations do not produce trees. It’s not a bijection.
62 / 112
![Page 63: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/63.jpg)
Counting Trees
Prufer codes
Sanity check
Could it be (n − 1)n−1?
n trees
2 13 4 > 34 27 > 16
Yeah, we’re definitely overcounting. But, we’re guaranteed not toundercount. Every tree has a representation in this scheme. But,some representations do not produce trees. It’s not a bijection.
63 / 112
![Page 64: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/64.jpg)
Counting Trees
Prufer codes
Sanity check
Could it be (n − 1)n−1?
n trees
2 13 4 > 34 27 > 16
Yeah, we’re definitely overcounting.
But, we’re guaranteed not toundercount. Every tree has a representation in this scheme. But,some representations do not produce trees. It’s not a bijection.
64 / 112
![Page 65: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/65.jpg)
Counting Trees
Prufer codes
Sanity check
Could it be (n − 1)n−1?
n trees
2 13 4 > 34 27 > 16
Yeah, we’re definitely overcounting. But, we’re guaranteed not toundercount.
Every tree has a representation in this scheme. But,some representations do not produce trees. It’s not a bijection.
65 / 112
![Page 66: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/66.jpg)
Counting Trees
Prufer codes
Sanity check
Could it be (n − 1)n−1?
n trees
2 13 4 > 34 27 > 16
Yeah, we’re definitely overcounting. But, we’re guaranteed not toundercount. Every tree has a representation in this scheme.
But,some representations do not produce trees. It’s not a bijection.
66 / 112
![Page 67: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/67.jpg)
Counting Trees
Prufer codes
Sanity check
Could it be (n − 1)n−1?
n trees
2 13 4 > 34 27 > 16
Yeah, we’re definitely overcounting. But, we’re guaranteed not toundercount. Every tree has a representation in this scheme. But,some representations do not produce trees.
It’s not a bijection.
67 / 112
![Page 68: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/68.jpg)
Counting Trees
Prufer codes
Sanity check
Could it be (n − 1)n−1?
n trees
2 13 4 > 34 27 > 16
Yeah, we’re definitely overcounting. But, we’re guaranteed not toundercount. Every tree has a representation in this scheme. But,some representations do not produce trees. It’s not a bijection.
68 / 112
![Page 69: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/69.jpg)
Counting Trees
Prufer codes
Prufer rule
Repeat the following procedure n − 2 times.
Find the smallestvalued leaf. Write down its parent. Delete the leaf.
3 3 4 2 7 10 10 4 5
69 / 112
![Page 70: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/70.jpg)
Counting Trees
Prufer codes
Prufer rule
Repeat the following procedure n − 2 times. Find the smallestvalued leaf.
Write down its parent. Delete the leaf.
3 3 4 2 7 10 10 4 5
70 / 112
![Page 71: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/71.jpg)
Counting Trees
Prufer codes
Prufer rule
Repeat the following procedure n − 2 times. Find the smallestvalued leaf. Write down its parent.
Delete the leaf.
3 3 4 2 7 10 10 4 5
71 / 112
![Page 72: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/72.jpg)
Counting Trees
Prufer codes
Prufer rule
Repeat the following procedure n − 2 times. Find the smallestvalued leaf. Write down its parent. Delete the leaf.
3 3 4 2 7 10 10 4 5
72 / 112
![Page 73: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/73.jpg)
Counting Trees
Prufer codes
Prufer rule
Repeat the following procedure n − 2 times. Find the smallestvalued leaf. Write down its parent. Delete the leaf.
3 3 4 2 7 10 10 4 5
73 / 112
![Page 74: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/74.jpg)
Counting Trees
Prufer codes
Prufer rule
Repeat the following procedure n − 2 times. Find the smallestvalued leaf. Write down its parent. Delete the leaf.
3
3 4 2 7 10 10 4 5
74 / 112
![Page 75: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/75.jpg)
Counting Trees
Prufer codes
Prufer rule
Repeat the following procedure n − 2 times. Find the smallestvalued leaf. Write down its parent. Delete the leaf.
3 3
4 2 7 10 10 4 5
75 / 112
![Page 76: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/76.jpg)
Counting Trees
Prufer codes
Prufer rule
Repeat the following procedure n − 2 times. Find the smallestvalued leaf. Write down its parent. Delete the leaf.
3 3 4
2 7 10 10 4 5
76 / 112
![Page 77: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/77.jpg)
Counting Trees
Prufer codes
Prufer rule
Repeat the following procedure n − 2 times. Find the smallestvalued leaf. Write down its parent. Delete the leaf.
3 3 4 2
7 10 10 4 5
77 / 112
![Page 78: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/78.jpg)
Counting Trees
Prufer codes
Prufer rule
Repeat the following procedure n − 2 times. Find the smallestvalued leaf. Write down its parent. Delete the leaf.
3 3 4 2 7
10 10 4 5
78 / 112
![Page 79: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/79.jpg)
Counting Trees
Prufer codes
Prufer rule
Repeat the following procedure n − 2 times. Find the smallestvalued leaf. Write down its parent. Delete the leaf.
3 3 4 2 7 10
10 4 5
79 / 112
![Page 80: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/80.jpg)
Counting Trees
Prufer codes
Prufer rule
Repeat the following procedure n − 2 times. Find the smallestvalued leaf. Write down its parent. Delete the leaf.
3 3 4 2 7 10 10
4 5
80 / 112
![Page 81: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/81.jpg)
Counting Trees
Prufer codes
Prufer rule
Repeat the following procedure n − 2 times. Find the smallestvalued leaf. Write down its parent. Delete the leaf.
3 3 4 2 7 10 10 4
5
81 / 112
![Page 82: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/82.jpg)
Counting Trees
Prufer codes
Prufer rule
Repeat the following procedure n − 2 times. Find the smallestvalued leaf. Write down its parent. Delete the leaf.
3 3 4 2 7 10 10 4 5
82 / 112
![Page 83: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/83.jpg)
Counting Trees
Prufer codes
Recover a tree
We can process any tree into a list.
But, can we recover the treefrom the list? Before we prove that we can, let’s do an example:
3 3 4 2 7 10 10 4 5
83 / 112
![Page 84: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/84.jpg)
Counting Trees
Prufer codes
Recover a tree
We can process any tree into a list. But, can we recover the treefrom the list?
Before we prove that we can, let’s do an example:
3 3 4 2 7 10 10 4 5
84 / 112
![Page 85: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/85.jpg)
Counting Trees
Prufer codes
Recover a tree
We can process any tree into a list. But, can we recover the treefrom the list? Before we prove that we can, let’s do an example:
3 3 4 2 7 10 10 4 5
85 / 112
![Page 86: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/86.jpg)
Counting Trees
Prufer codes
Recover a tree
We can process any tree into a list. But, can we recover the treefrom the list? Before we prove that we can, let’s do an example:
3 3 4 2 7 10 10 4 5
86 / 112
![Page 87: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/87.jpg)
Counting Trees
Prufer codes
Recover a tree
We can process any tree into a list. But, can we recover the treefrom the list? Before we prove that we can, let’s do an example:
3 3 4 2 7 10 10 4 5
87 / 112
![Page 88: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/88.jpg)
Counting Trees
Prufer codes
4 by 4
88 / 112
![Page 89: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/89.jpg)
Counting Trees
Prufer codes
Thinking inductivelyHere’s a 6-vertex tree in Prufer encoding: 1 1 3 1.
In what sense is it built out of a 5-vertex encoding? Take thevertex x that is the “first” leaf. Here, x = 2. Remove it, thenrenumber the vertices, decrementing anything larger than x . Thething to note is that the resulting tree and encoding still match!
89 / 112
![Page 90: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/90.jpg)
Counting Trees
Prufer codes
Thinking inductivelyHere’s a 6-vertex tree in Prufer encoding: 1 1 3 1.
In what sense is it built out of a 5-vertex encoding? Take thevertex x that is the “first” leaf. Here, x = 2. Remove it, thenrenumber the vertices, decrementing anything larger than x . Thething to note is that the resulting tree and encoding still match!
90 / 112
![Page 91: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/91.jpg)
Counting Trees
Prufer codes
Thinking inductivelyHere’s a 6-vertex tree in Prufer encoding: 1 1 3 1.
In what sense is it built out of a 5-vertex encoding?
Take thevertex x that is the “first” leaf. Here, x = 2. Remove it, thenrenumber the vertices, decrementing anything larger than x . Thething to note is that the resulting tree and encoding still match!
91 / 112
![Page 92: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/92.jpg)
Counting Trees
Prufer codes
Thinking inductivelyHere’s a 6-vertex tree in Prufer encoding: 1 1 3 1.
In what sense is it built out of a 5-vertex encoding? Take thevertex x that is the “first” leaf.
Here, x = 2. Remove it, thenrenumber the vertices, decrementing anything larger than x . Thething to note is that the resulting tree and encoding still match!
92 / 112
![Page 93: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/93.jpg)
Counting Trees
Prufer codes
Thinking inductivelyHere’s a 6-vertex tree in Prufer encoding: 1 1 3 1.
In what sense is it built out of a 5-vertex encoding? Take thevertex x that is the “first” leaf. Here, x = 2.
Remove it, thenrenumber the vertices, decrementing anything larger than x . Thething to note is that the resulting tree and encoding still match!
93 / 112
![Page 94: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/94.jpg)
Counting Trees
Prufer codes
Thinking inductivelyHere’s a 6-vertex tree in Prufer encoding: 1 1 3 1.
In what sense is it built out of a 5-vertex encoding? Take thevertex x that is the “first” leaf. Here, x = 2. Remove it, thenrenumber the vertices, decrementing anything larger than x .
Thething to note is that the resulting tree and encoding still match!
94 / 112
![Page 95: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/95.jpg)
Counting Trees
Prufer codes
Thinking inductivelyHere’s a 6-vertex tree in Prufer encoding: 1 1 3 1.
In what sense is it built out of a 5-vertex encoding? Take thevertex x that is the “first” leaf. Here, x = 2. Remove it, thenrenumber the vertices, decrementing anything larger than x . Thething to note is that the resulting tree and encoding still match!
95 / 112
![Page 96: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/96.jpg)
Counting Trees
Prufer codes
Proof
Theorem: For every string a ∈ [1, n]n−2 (n ≥ 2), there is a uniquetree T .
Proof: Build-down induction on n.
Base Case (n = 2): There is only one tree (a 1–2 segment) andonly one encoding string (the null string).
Inductive Step (n + 1): Consider a string a of length n − 1. In thetree T encoded by a, the leaf with the smallest label x must belinked to a1.
Consider the string a′ formed by removing a1 from a and thensubtracting one from every value in a that’s larger than x . By theinductive hypothesis, there is a unique tree T0 constructed from a′.We can construct a unique tree T from T0 by adding 1 to thevalues in T0 that are x or above, then adding the edge (x , a1).
96 / 112
![Page 97: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/97.jpg)
Counting Trees
Prufer codes
Proof
Theorem: For every string a ∈ [1, n]n−2 (n ≥ 2), there is a uniquetree T .
Proof: Build-down induction on n.
Base Case (n = 2): There is only one tree (a 1–2 segment) andonly one encoding string (the null string).
Inductive Step (n + 1): Consider a string a of length n − 1. In thetree T encoded by a, the leaf with the smallest label x must belinked to a1.
Consider the string a′ formed by removing a1 from a and thensubtracting one from every value in a that’s larger than x . By theinductive hypothesis, there is a unique tree T0 constructed from a′.We can construct a unique tree T from T0 by adding 1 to thevalues in T0 that are x or above, then adding the edge (x , a1).
97 / 112
![Page 98: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/98.jpg)
Counting Trees
Prufer codes
Proof
Theorem: For every string a ∈ [1, n]n−2 (n ≥ 2), there is a uniquetree T .
Proof: Build-down induction on n.
Base Case (n = 2): There is only one tree (a 1–2 segment) andonly one encoding string (the null string).
Inductive Step (n + 1): Consider a string a of length n − 1.
In thetree T encoded by a, the leaf with the smallest label x must belinked to a1.
Consider the string a′ formed by removing a1 from a and thensubtracting one from every value in a that’s larger than x . By theinductive hypothesis, there is a unique tree T0 constructed from a′.We can construct a unique tree T from T0 by adding 1 to thevalues in T0 that are x or above, then adding the edge (x , a1).
98 / 112
![Page 99: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/99.jpg)
Counting Trees
Prufer codes
Proof
Theorem: For every string a ∈ [1, n]n−2 (n ≥ 2), there is a uniquetree T .
Proof: Build-down induction on n.
Base Case (n = 2): There is only one tree (a 1–2 segment) andonly one encoding string (the null string).
Inductive Step (n + 1): Consider a string a of length n − 1. In thetree T encoded by a, the leaf with the smallest label x must belinked to a1.
Consider the string a′ formed by removing a1 from a and thensubtracting one from every value in a that’s larger than x . By theinductive hypothesis, there is a unique tree T0 constructed from a′.We can construct a unique tree T from T0 by adding 1 to thevalues in T0 that are x or above, then adding the edge (x , a1).
99 / 112
![Page 100: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/100.jpg)
Counting Trees
Prufer codes
Proof
Theorem: For every string a ∈ [1, n]n−2 (n ≥ 2), there is a uniquetree T .
Proof: Build-down induction on n.
Base Case (n = 2): There is only one tree (a 1–2 segment) andonly one encoding string (the null string).
Inductive Step (n + 1): Consider a string a of length n − 1. In thetree T encoded by a, the leaf with the smallest label x must belinked to a1.
Consider the string a′ formed by removing a1 from a and thensubtracting one from every value in a that’s larger than x .
By theinductive hypothesis, there is a unique tree T0 constructed from a′.We can construct a unique tree T from T0 by adding 1 to thevalues in T0 that are x or above, then adding the edge (x , a1).
100 / 112
![Page 101: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/101.jpg)
Counting Trees
Prufer codes
Proof
Theorem: For every string a ∈ [1, n]n−2 (n ≥ 2), there is a uniquetree T .
Proof: Build-down induction on n.
Base Case (n = 2): There is only one tree (a 1–2 segment) andonly one encoding string (the null string).
Inductive Step (n + 1): Consider a string a of length n − 1. In thetree T encoded by a, the leaf with the smallest label x must belinked to a1.
Consider the string a′ formed by removing a1 from a and thensubtracting one from every value in a that’s larger than x . By theinductive hypothesis, there is a unique tree T0 constructed from a′.
We can construct a unique tree T from T0 by adding 1 to thevalues in T0 that are x or above, then adding the edge (x , a1).
101 / 112
![Page 102: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/102.jpg)
Counting Trees
Prufer codes
Proof
Theorem: For every string a ∈ [1, n]n−2 (n ≥ 2), there is a uniquetree T .
Proof: Build-down induction on n.
Base Case (n = 2): There is only one tree (a 1–2 segment) andonly one encoding string (the null string).
Inductive Step (n + 1): Consider a string a of length n − 1. In thetree T encoded by a, the leaf with the smallest label x must belinked to a1.
Consider the string a′ formed by removing a1 from a and thensubtracting one from every value in a that’s larger than x . By theinductive hypothesis, there is a unique tree T0 constructed from a′.We can construct a unique tree T from T0 by adding 1 to thevalues in T0 that are x or above, then adding the edge (x , a1).
102 / 112
![Page 103: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/103.jpg)
Counting Trees
Prufer codes
Summing up
We have a scheme for encoding trees as lists.
It always works. Wehave a scheme for turning lists into trees. It always works. Wehave a bijection.
How many lists? n − 2 choices of numbers from 1 to n. So, nn−2.Does that fit?
n trees
2 13 34 16
103 / 112
![Page 104: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/104.jpg)
Counting Trees
Prufer codes
Summing up
We have a scheme for encoding trees as lists. It always works.
Wehave a scheme for turning lists into trees. It always works. Wehave a bijection.
How many lists? n − 2 choices of numbers from 1 to n. So, nn−2.Does that fit?
n trees
2 13 34 16
104 / 112
![Page 105: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/105.jpg)
Counting Trees
Prufer codes
Summing up
We have a scheme for encoding trees as lists. It always works. Wehave a scheme for turning lists into trees.
It always works. Wehave a bijection.
How many lists? n − 2 choices of numbers from 1 to n. So, nn−2.Does that fit?
n trees
2 13 34 16
105 / 112
![Page 106: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/106.jpg)
Counting Trees
Prufer codes
Summing up
We have a scheme for encoding trees as lists. It always works. Wehave a scheme for turning lists into trees. It always works.
Wehave a bijection.
How many lists? n − 2 choices of numbers from 1 to n. So, nn−2.Does that fit?
n trees
2 13 34 16
106 / 112
![Page 107: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/107.jpg)
Counting Trees
Prufer codes
Summing up
We have a scheme for encoding trees as lists. It always works. Wehave a scheme for turning lists into trees. It always works. Wehave a bijection.
How many lists? n − 2 choices of numbers from 1 to n. So, nn−2.Does that fit?
n trees
2 13 34 16
107 / 112
![Page 108: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/108.jpg)
Counting Trees
Prufer codes
Summing up
We have a scheme for encoding trees as lists. It always works. Wehave a scheme for turning lists into trees. It always works. Wehave a bijection.
How many lists?
n − 2 choices of numbers from 1 to n. So, nn−2.Does that fit?
n trees
2 13 34 16
108 / 112
![Page 109: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/109.jpg)
Counting Trees
Prufer codes
Summing up
We have a scheme for encoding trees as lists. It always works. Wehave a scheme for turning lists into trees. It always works. Wehave a bijection.
How many lists? n − 2 choices of numbers from 1 to n.
So, nn−2.Does that fit?
n trees
2 13 34 16
109 / 112
![Page 110: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/110.jpg)
Counting Trees
Prufer codes
Summing up
We have a scheme for encoding trees as lists. It always works. Wehave a scheme for turning lists into trees. It always works. Wehave a bijection.
How many lists? n − 2 choices of numbers from 1 to n. So, nn−2.
Does that fit?
n trees
2 13 34 16
110 / 112
![Page 111: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/111.jpg)
Counting Trees
Prufer codes
Summing up
We have a scheme for encoding trees as lists. It always works. Wehave a scheme for turning lists into trees. It always works. Wehave a bijection.
How many lists? n − 2 choices of numbers from 1 to n. So, nn−2.Does that fit?
n trees
2 13 34 16
111 / 112
![Page 112: Counting Trees - Brown University · 2020-04-29 · Counting Trees Attempt 2: Building up Ways to add a vertex So, let’s be careful to only generate trees. Here’s the thought.](https://reader035.fdocuments.in/reader035/viewer/2022070722/5f01bec67e708231d400d52d/html5/thumbnails/112.jpg)
Counting Trees
Prufer codes
Summing up
We have a scheme for encoding trees as lists. It always works. Wehave a scheme for turning lists into trees. It always works. Wehave a bijection.
How many lists? n − 2 choices of numbers from 1 to n. So, nn−2.Does that fit?
n trees
2 13 34 16
112 / 112