Blowing in the Wind CS 15-251 Lecture 23

Blowing in the Wind
Lecture 23
CS 15-251
root
a
a
root
b
b
b
A tree.
a
methane
H
H
propane
H
C
C
H
C
H
H
C
H
H
H
C
H
H
C
H
H
C
H
H
C
H
H
H
H
C
H
H
C
H
H
H
H
H
H
ethane
butane
H
some saturated hydrocarbons
Putting a picture into words…
A tree is a connected
graph with no cycles.
These are not trees…
Theorem: Let G be a graph with n
nodes and e edges.
The following are equivalent:
1. G is a tree (connected, acyclic).
2. Every two nodes of G are
joined by a unique path.
3. G is connected and n = e + 1.
4. G is acyclic and n = e + 1.
Proof:
Show 1  2  3  4  1.
(1) (2)
G is a tree  u  v, u and v are
connected by a unique path
contrapositive (not 2) (not 1)
Fix u and v. If there is no path
between them, then G is not a tree.
Let p1 and p2 be two distinct paths
from u to v.
p2
w
w
u
v
w’ p1
p2
Let w be the first point along p1 whose
next edge is different along p2 than p1.
Let w’ be the first point along p1 after
w whose successor is also in p2.
p1
w’
A cycle.
G is not
a tree.
(2) (3)
Every two vertices of G are connected by
a unique path  G is connected and n=e+1
Clearly G is connected. We show that
n=e+1 by induction on n.
Base cases: n=1
n=2
Assume the claim is true for all
graphs with fewer than n nodes.
When we remove an edge from G we break
it into exactly two connected components.
unique path
from u to v
By induction, each piece has one fewer
edge than nodes. (n-2)+1 edges = n-1 edges
u
v
(3) (4)
G is connected and n=e+1 
G is acyclic and n=e+1
Suppose G has a cycle of length r.
The cycle has r nodes and r edges.
For each node not on the cycle, we
associate one of its edges which
brings us closer to the cycle.
Each non-cycle node is now
associated with a unique non-cycle
edge. This contradicts n = e+1.
(4)  (1)
G is acyclic and n=e+1 
G is acyclic and connected
If G is not connected, then it has k > 1
connected components G1,G2,…,Gk .
Each is acyclic and connected, and
therefore a tree.
We already know (1)  (4)
So n1  e1  1
n2  e2  1
nk  ek  1
 k 
ni  n    ei   k  e  k  e  1 

i 1
 i 1 
k
Question:
How many trees are there with
four nodes?
2 trees
16 labeled trees
a
c
b
d
Question:
How many labeled graphs on
n nodes are there?


2
n
2
n
Each of   edges is either
2
present or not.
Question
How many labeled trees on n
nodes are there?
n
Why?
n 2
The proof will use the correspondence
principle.
Each labeled tree on n nodes
corresponds to


n 2
a sequence in 1, 2, , n , i.e., (n-2)
numbers each in the range 1..n  .
How to make a sequence from a tree.
Loop through i from 1 to n-2
Let l be the degree-1 node
with the lowest label.
Define the ith element of
the sequence as the label of
the node adjacent to l.
Delete the node l from the
tree.
8
5
Example:
4
3
1,3,3,4,4,4
1
7
2
6
How to reconstruct the unique tree
from a sequence S.
Let I  1,2,3, , n
empty
sequence
Loop until S=
Let l = smallest # in I but not in S
Let s = first label in sequence S
•Add edge {l, s} to the tree.
•Delete l from I.
•Delete s from S.
Add edge {l, s} to the tree,
where I  l , s
1
1,3,3,4,4,4
2
3
1
3
5
4
3
4 4
4
6 7 8
The problem of counting the
number of n-node trees is
much harder.
It can be handled by Polya
enumeration theory.

  
T ( x )  x e r 1
T xr
The coefficient of xk in T(x)
is the # of rooted trees on k
nodes.
A Game: n point sprouts
Start with n points on the page.
Two players alternate moves.
A move consists of drawing and edge
between two points and sprouting a
new point somewhere along the edge.
Restrictions:
•Edges can’t cross
•No point can have degree greater
than three.
A Game: n point sprouts
You lose if you can’t make a
legal move.
(You are allowed to place an
edge between a point and
itself as shown below.)
new point
Question:
Why does n-node sprouts
terminate?
How many moves might it
take?
For a given position, define its
degree of freedom as
3
# of
nodes
2
# of
edges
Thus, the starting position in
n-node sprouts has degree of
freedom
3n
Each move drops the degree
of freedom by 1.
(We add 1 node, but 2 edges.)
Theorem:
The total # of moves in n-node
sprouts is
 3n
Brussels Sprouts
Nodes look like this:
Sprouts look like this:
Questions:
Why does it terminate?
How many moves?
Is there a winning strategy?
Each
has 4 liberties.
There are 4n liberties at
start of an n-node game.
Each move uses up two more
liberties and creates two
more.
At any point in the game
there are 4n liberties.
The board starts as 1 region,
but it can be split into many.
1
1
2
3
Each time a region is created, a
liberty falls inside it. I.e., every
region has at least one liberty.
If # of regions < # of liberties
then there is still at least one
legal move to be played.
Some region must still have
at least two liberties.
If # regions = # liberties,
then the game is over!
Each liberty must be in a
separate region, i.e., each
region has at least one
liberty.
Call a move “region creating” if
it adds one to the total # of
regions.
We start with 1 region. We finish
when we have 4n regions.
Thus:
Each game has exactly 4n-1
region creating moves.
But what about
the moves that
don’t create
regions?
At the start the n +’s can be viewed as
n components.
Two +’s are in the same component if
and only if there is a path from one to
the other.
A region-creating move must go
between +’s in the same component.
Thus, a move that does not
create a region must merge
two components into one.
At the start there are n
components.
At the end there is 1
component.
In any game there are
exactly n-1 moves that do
not create a region.
4n  1 
region
creating
moves

n 1
component
merging
moves
5n  2
moves per game
odd n  first player wins
even n  second player wins