Tree

You might also like

Download as odp, pdf, or txt
Download as odp, pdf, or txt
You are on page 1of 33

Module3

What’s a tree?

A tree is a connected
graph with no cycles
Tree
Not Tree
Not Tree
Tree
More on trees
➢A tree has to be a simple graph.
➢Trees appear in numerous instances.
Genealogy of a family
A river with its tributaries and subtributaries
Sorting of mail
How Many n-Node Trees?
1:

2:

3:

4:

5:
How many labeled trees are
there with three nodes?

1 2 3

1 3 2

2 1 3
How many labeled trees are
there with four nodes?
a c
b d
Cayley's
formula
No of trees possible with
n vertices = n (n-2)

When N=4

4 (4-2)
=16
SOME PROPERTIES OF
TREES
Theorem 3.1: There is one and only one path between

every pair of vertices in a tree, T.

Theorem 3.2: If in a graph G there is one and only one


path between every pair of vertices, G is a tree.

Theorem 3.3: A tree with n vertices has n-1 edges.



Theorem 3.1
Theorem 3.1: There is one and only one path between

every pair of vertices in a tree, T.


Given 1.
: G is a tree (connected, acyclic)
2. Exactly one path between
every pair of vertices

Proof: (by contradiction)


Assume G is a tree that has two
nodes connected by two different
paths:

Then there exists a cycle!


Theorem 3.2
Theorem 3.2: If in a graph G there is one and only one

path between every pair of vertices, G is a tree.


THEOREM 3.2
Given : There is one and only one path between every pair of
vertices
Prove ? : G is a tree(Connected, Circuitless)

Existence of a path between every pair of vertices assures


that G is connected. A circuit in a graph (with two or more
vertices) implies that there is at least one pair of vertices a, b
such that there are two distinct paths between a and b. Since
G has one and only one path between every pair of vertices,
G can have no circuit. Therefore, G is a tree.
THEOREM 3.3
Theorem 3.3 A tree with n vertices has n-1 edges.
A connected graph is said to be
minimally connected if removal of any
one edge from it disconnects the graph.
Proof: (by induction)

The theorem will be proved by induction on


the number of vertices. It is easy to see that
the theorem is true for n = 1, 2, and 3 .
For n = 1,
• T is a tree with one vertex
• no. of edges = 0
• Hence the theorem is true for n = 1.
For n = 2,
T is a tree with two vertices.
no. of edges = 1

Let G have n nodes and let x and y be adjacent

G1 G2
x y

Let n1,e1 be number of nodes and edges in G1


Then n = n1 + n2 = e1 + e2 + 2 = e + 1
Suppose the theorem is true for n = k ∴T, a tree
with k vertices has (k – 1) edges.
Assume it is true for <n
To prove the theorem is true for n.Let ek be an
edge between two vertices vi and vj of T.If ek is
deleted, there is no path between vi and vj. [i.e
ek is a unique path between vi and vj]
 The sub-graph  (T – ek)  will have two
components T1 and T2 with n1 and n2 vertices
respectively, where
        n1 + n2 = n  ;  n1, n2 < k
T1 is a tree with n1 vertices.∴T1 has (n1 - 1)
edges. Also T2 is a tree with n2 vertices.∴ T2
has (n2 - 1) edges.
∴Number of edges in T1 and T2
  = (n1 - 1) + (n2 - 1) = n1 + n2 – 2 =  n – 2
    Thus, the number of edges in T =n1 −1+n2
−1+1 = n1 +n2 −1 = n−1
  = (n - 2) + 1(removed edge ek)  = n-1
The theorem is true for n.Hence by induction
method, the theorem is true for every positive
integer n.
Let us now consider a tree T with n vertices. In T
let ek be an edge with end vertices vi and vj.
According to Theorem 3-1, there is no other
path between vi and vj , except ek. Therefore,
deletion of ek from T will disconnect the graph,
as shown in Figure. Furthermore, T—ek consists
of exactly two components, and since there
were no circuits, each of these components is a
tree. Both these trees, t1 and t2 , have fewer
than n vertices each, and therefore, by the
induction hypothesis, each contains one less
edge than the number of vertices in it. Thus T—
ek consists of n—2 edges (and n vertices).
Theorem 3.5: A graph is a tree if and only if it
is minimally connected.

Given:G is a tree(removal of one edge


disconnects the graph since there is only
one path between any two pair of
vertices)
? G is minimally connected(removal of
edge disconnects the graph)
Assume the contrary that removal of one
edge does not disconnect the
graph,which means we have more than
one path between any two vertices
This is a contradiction to our assumption that
G is a tree.since G is a tree, G contains no
cycles and deletion of any edge from G
disconnects the graph. Hence G is minimally
connected
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
5. G is acyclic and if any two non-
adjacent nodes are joined by an edge,
the resulting graph has exactly one
cycle
3. G is connected and n = e + 1
4. G is acyclic and n = e + 1
Proof: (by contradiction)
Assume G is connected with n = e +
1, and G has a cycle containing k
nodes
k nodes

Note that the cycle has k nodes and k edges


Start adding nodes and edges until you
cover the whole graph
Number of edges in the graph will be at least n
Corollary: Every nontrivial tree has at
least two endpoints (points of degree 1)
Proof (by contradiction):
Assume all but one of the points in the
tree have degree at least 2

In any graph, sum of the degrees =2e

Then the total number of edges in the


tree is at least (2n-1)/2 = n - 1/2 > n - 1
How many labeled trees are
there with five nodes?

5 5 x 4 x3 5!/ 2
labelings
labelings labelings

125 labeled trees


How many labeled trees are
there with n nodes?
3 labeled trees with 3 nodes
16 labeled trees with 4 nodes
125 labeled trees with 5 nodes

nn-2 labeled trees with n nodes


Cayley’s Formula
The number of labeled
trees on n nodes is nn-2
The proof will use the correspondence principle

Each labeled tree on n nodes


corresponds to
A sequence in {1,2,…,n}n-2 (that is, n-2
numbers, each in the range [1..n])
How to make a sequence from a
tree?through i from 1 to n-2
Loop
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

Example: 5 8
3 4
1 7
2 6
1 3 3 4 4 4
How to reconstruct the unique tree
from a sequence S:
Let I = {1, 2, 3, …, n}
Loop until S is empty
Let i = smallest # in I but not in S
Let s = first label in sequence S
Add edge {i, s} to the tree
Delete i from I 8
5
Delete s from S 3 4
1 7
Add edge {a,b}, where I = {a,b} 2 6
1 3 3 4 4 4

You might also like