Trees Tree is connected graph without any circuits

  • Slides: 18
Download presentation
Trees

Trees

Tree is connected graph without any circuits or cycles Ex. Trees with one, two,

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

Properties • There is one and only one path between every pair of vertices

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 theorem.

Theorem If in a graph G, there is one and only one path between

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 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.

Theorem A tree with n vertices has (n - 1) edges Proof Let T

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 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.

Suppose theorem is true for n = k T, a tree with k vertices

Suppose theorem is true for n = k T, a tree with k vertices has (k – 1) edges. To prove 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 T 1 and T 2 with k 1 and k 2 vertices respectively, where k 1 + k 2 = k + 1 ; k 1, k 2 k.

∵ T 1 is a tree with k 1 vertices. T 1 has (k

∵ T 1 is a tree with k 1 vertices. T 1 has (k 1 - 1) edges. Also T 2 is a tree with k 2 vertices. T 2 has (k 2 - 1) edges. Number of edges in T 1 and T 2 = (k 1 - 1) + (k 2 - 1) = k 1 + k 1 – 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, theorem is true for every positive integer n.

Theorem Any connected graph with n vertices and (n - 1) edges is a

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.

We continue this process of locating edges that are not bridges and deleting them

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=1 but k 1 Which can not be true. Hence T is a tree.

Theorem In any tree (with two or more vertices), there at least two pendant

Theorem In any tree (with two or more vertices), there 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 d 1 + d 2 + … + dn = 2 n – 2

 If degree of each vertex is more than 1, then sum of the

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

Rooted Trees A tree in which one vertex (called the root) is distinguished from

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.

Binary Tree A tree with n vertices (n 3) is called binary tree in

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

Properties The number of vertices in a binary tree is always odd Proof Let

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.

Theorem Number of pendant vertices in a binary tree is (n+1)/2 Proof Let T

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 = 3 n – 2 p – 1 Since sum of degrees of all vertices in a graph is twice the number of edges.

 Number of edges in T = ½(3 n – 2 p - 1)

Number of edges in T = ½(3 n – 2 p - 1) Also, number of edges in a tree of n vertices = n – 1 ½(3 n – 2 p - 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.

Height of Tree The maximum level, lmax in a binary tree is called the

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 = log 2(n + 1) - 1 Maximum possible height of an n-vertex binary tree is max lmax = (n - 1)/2.

Path Length Also called external path length of a tree = Sum of the

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.