Presentation is loading. Please wait.

Presentation is loading. Please wait.

Trees.

Similar presentations


Presentation on theme: "Trees."— Presentation transcript:

1 Trees

2 Tree is connected graph without any circuits or cycles
Ex. Trees with one, two, three and four vertices are A tree must have at least one vertex. A tree is a simple graph

3 Properties There is one and only one path between every pair of vertices in a tree Proof Let T be a tree  T is a connected graph There exists at least one path between every pair of vertices in T. Suppose that there are two distinct paths between two vertices a and b of T. Union of these two paths will contain a circuit, which is a contradiction that T is a tree. Hence the theorem.

4 Theorem If in a graph G, there is one and only one path between every pair of vertices, then G is a tree. Proof Since there exists a path between every pair of vertices in graph G.  G is connected. Suppose G is not a tree There is a circuit in G There are at least two vertices a and b in G, having two distinct paths But it is given that there is one and only one path between every pair of vertices in G. Hence the graph is a tree.

5 Theorem A tree with n vertices has (n - 1) edges Proof Let T be a tree with n vertices. T is a connected graph. To prove that T has (n - 1) edges. This theorem will be proved by induction method. For n = 1, T is a tree with one vertex. no. of edges = 0 the theorem is true for n = 1. For n = 2, T is a tree with two vertices. no. of edges = 1  The theorem is true for n = 2.

6 Suppose the theorem is true for n = k
T, a tree with k vertices has (k – 1) edges. To prove the theorem is true for n = k + 1 Let e be an edge between two vertices v & w of T If e is deleted, there is no path between v and w. [∵ e is a unique path between v & w] The sub-graph (T – e) will have two components T1 and T2 with k1 and k2 vertices respectively, where k1 + k2 = k + 1 ; k1, k2  k.

7 ∵ T1 is a tree with k1 vertices.
 T1 has (k1 - 1) edges. Also T2 is a tree with k2 vertices.  T2 has (k2 - 1) edges. Number of edges in T1 and T2 = (k1 - 1) + (k2 - 1) = k1 + k1 – 2 = k + 1 – 2 = k - 1 Thus, the number of edges in T = (k - 1) + 1 = k The theorem is true for n = k + 1. Hence by induction method, the theorem is true for every positive integer n.

8 Theorem Any connected graph with n vertices and (n - 1) edges is a tree. Proof Suppose the connected graph T with n vertices and (n - 1) edges is not a tree. T has an edge e that is not a bridge. If e is deleted, the subgraph T – e is still a connected graph with n vertices and (n - 2) edges.

9 We continue this process of locating edges that are not bridges and deleting them until we get a connected subgraph T’ with n vertices and (n - k) edges, where k  1 in which every edge is a bridge. Now, T’ is a tree with n vertices. T’ has (n - 1) edges. Thus, n – 1 = n – k where k  1 k = but k  1 Which can not be true. Hence T is a tree.

10 Theorem In any tree (with two or more vertices), there are at least two pendant vertices. Proof Let T be a tree with n vertices. T has (n - 1) edges. Sum of degrees of n vertices in T = 2 (n - 1) Suppose di is the degree of ith vertex where i = 1, 2, …, n d1 + d2 + … + dn = 2n – 2

11 Distance If degree of each vertex is more than 1, then
sum of the degrees of n vertices is at least 2n. But the sum of degrees of all the vertices = 2n – 2. There are at least two vertices with degree 1. [∵ no vertex can be of degree zero] Hence there are at least two pendant vertices. Distance In a connected graph G, the distance d(v1, v2) between two vertices v1 and v1 is the length of the shortest path between them.

12 Rooted Trees A tree in which one vertex (called the root) is distinguished from all the others is called a rooted tree. Rooted trees with four vertices Non-rooted trees are called free trees or simply trees.

13 Binary Tree A tree with n vertices (n  3) is called binary tree in which there is exactly one vertex of degree two, each of the remaining vertices is of degree one or three. The vertex of degree 2 is called the root as it is distinct from all other vertices, it serves as a root. Binary tree is always a rooted tree. Non-pendant vertex is called Internal Vertex

14 Properties The number of vertices in a binary tree is always odd Proof
Let n be the number of vertices in a binary tree. Since there is exactly one vertex of even degree.  All the remaining (n -1) vertices are of odd degrees. Since the number of odd degree vertices in a graph is always even. (n - 1) is even. Hence n is odd.

15 Theorem Number of pendant vertices in a binary tree is (n+1)/2 Proof Let T be the binary tree of n vertices and p be the number of pendant vertices in T. Also there is one vertex of degree two in T. n – p – 1 is the number of vertices of degree three Sum of degrees of all vertices in T = p + 3(n – p - 1) + 2 = 3n – 2p – 1 Since sum of degrees of all vertices in a graph is twice the number of edges.

16 Number of edges in T = ½(3n – 2p - 1)
Also, number of edges in a tree of n vertices = n – 1 ½(3n – 2p - 1) = n – 1 p = (n + 1)/2 The number of internal vertices in a binary tree is one less than the number of pendant vertices. In a binary tree, a vertex vi is said to be at level li if vi is at a distance of li from the root.

17 Height of Tree The maximum level, lmax in a binary tree is called the height of the tree. Minimum possible height of an n-vertex binary tree is min lmax =  log2(n + 1) - 1 Maximum possible height of an n-vertex binary tree is max lmax = (n - 1)/2.

18 Path Length Also called external path length of a tree
= Sum of the path lengths from the root to all pendant vertices. The path length of a binary tree is often directly related to the execution time of an algorithm. A binary tree with minimum possible height gives the minimum path length for a given n.


Download ppt "Trees."

Similar presentations


Ads by Google