Presentation is loading. Please wait.

Presentation is loading. Please wait.

Section10.1: Introduction to Trees

Similar presentations


Presentation on theme: "Section10.1: Introduction to Trees"— Presentation transcript:

1 Section10.1: Introduction to Trees
Ms.Amal El Sayed Chapter10:Trees Section10.1: Introduction to Trees Definition1: a tree is a connected undirected graph with no simple circuits. Remark: a tree can not contain multiple edges or loops. Example1: which of the graphs are trees?

2 Solution: the trees are a,c,e, and f (are simple graph with no circuit) b is not a tree because it is not connected d is not a tree because it has a circuit b,c,d,b. Theorem1: An undirected graph is a tree if and only if there is a unique simple path between any two of its vertices. Definition: A rooted tree is a tree in which one vertex has been designated as the root and every edge is directed away from the root. Example2:

3 Remarks: 1) We usually draw a rooted tree with its root at the top of the graph.
2) The arrows indicating the direction of the edges in a rooted tree can be omitted, because the choice of root determines the directions of the edges. Tree terminology: suppose T is a rooted tree. If V is a vertex in T, other than the root. The parent of V is the unique vertex u such that there is a directed edge from U to V. When U is the parent of V, V is called a child of U. Vertices with the same parent are called siblings. Ancestors of a vertex is its parent, its parent’s parent, and so on. Descendants of a vertex V are those vertices that have V as ancestor. A vertex of a tree is called a leaf if it has no children. vertices that have children are called internal vertices. If a is a vertex in a tree, the sub tree with a as its root is the sub graph of the tree consisting of a and its descendants and all edges incident to these descendants.

4 Example3: Answer these questions about the rooted tree illustrated.
1) Which vertex is a root? Answer: a 2) Which vertices are internal? Answer: a,b,c,d,f,h,j,q, and t 3) Which vertices are leaves? Answer: e,l,m,n,g,o,p,s,u,r,k,i. 4) Which vertices are children of j? Answer: q and r 5) Which vertex is the parent of h? Answer: c

5 6) Which vertices are siblings of o?
Answer: p 7) Which vertices are ancestors of m? Answer: f,b,a 8) Which vertices are descendants of b? Answer: e,f,l,m,n 9) What is the sub tree rooted at d? Answer: the sub tree rooted at d is. Definition3: a rooted tree is called an m-ary tree if every internal vertex has no more than m children. The tree is called a full m – ary tree if every internal vertex has exactly m children. An m-ary tree with m = 2 is called a binary tree.

6 Example: refer to the last rooted tree
Example: refer to the last rooted tree. Is this rooted tree a full m-ary tree for some positive integer m? Answer: no, it is 3-ary tree. (every internal vertex has no more than 3 children) Example4 page 687. What are the left and right children of d in the binary tree T? what are the left and right sub trees of c? Answer: the left child of d is f; the right child of d is g; the left sub trees of c is The right sub trees of c is

7 Read Trees as Models Examples 5,6,7, and 8.
Properties of Trees: Theorem: a tree with n vertices has n-1 edges. Theorem: a full m-ary tree with i internal vertices contains n = mi + 1 vertices Theorem: a full m-ary tree with. n vertices has i = (n-1)/m internal vertices and l = [(m-1)n+1]/m leaves. i internal vertices has n = mi + 1 vertices and l = (m-1)i+ 1 leaves. L leaves has n = (ml – 1)/(m-1)vertices and i = (l-1)/(m-1) internal vertices. Example5: 1) how many edges does a tree with 10,000 vertices have. Answer: the number of edges are n-1 where n = 10,000 The number of edges n = 10,000-1=9999 2) How many vertices does a full 5-ary tree with 100 internal vertices have? Answer: number of vertices n = mi+1 where m=5 and i=100 so n = 5(100)+1=501 vertex. 3) How many edges does a full binary tree with 1000 internal vertices have? Answer: m=2,i=1000 The number of vertices n=mi+1=2(1000)+1 n=2001 so the no. of edges are n-1=2000 edges. 4) How many leaves does a full 3-ary tree with 100 vertices have?

8 Solution: m=3, n=100 L =[ (m-1)n+1]/m =[ (3-1)(100)+1]/3 =[ 200+1]/3 = 201/3 = 67leaves Example6: suppose that someone starts a chain letter. Each person who receives the letter is asked to send it to four other people. Some people do this, but others do not send any letters. How many people have seen the letter, including the first person, if no one receive more than one letter and if the chain letter ends after there have been 100 people who read it but did not send it out? How many people sent out the letter. Answer: the chain letter can be represented using a 4-ary tree. Interval vertices =1= the people who sent out the letter leaves =l= the people who did not send it out = 100 people find n?? And i ?? Where n = people who seen the letter n = (ml-1)/(m-1) = (4(100)-1)/(4-1 )= 133 people. i = (l-1)/(m-1 )= (100 -1)/(4-1 )= 99/3 = 33 people sent out the letter. Definition: the level of a vertex v in a rooted tree is the length of the unique path from the root to this vertex. Definition: the height of a rooted tree is the maximum of the levels of vertices. Remark: the height of a rooted tree is the length of the longest path from the root to any vertex. Example: refer to the rooted tree of example 3(slide no: 4). Find the level of each vertex. Find the height of this rooted tree.

9 solution: the vertex a has level 0.
The vertices: b,c, and d have level 1. The vertices: e,f,g,h,I,j,k have level 2. The vertices: l,m,n,o,p,q and r have level 3. The vertices: s and t have level 4. The height u has level 5. The height of this rooted tree = the length of the largest path from a = 5. Definition: a rooted m-ary tree of height h is balanced if all leaves are at levels h or h-1. Example11 page692: consider the following rooted trees. Solution: the height of is 4.the leaves are at level 3,and 4,so it is balanced. the height of is 4,The leaves of are at level 2,3, and 4. So it is not balanced.

10 Theorem: there are at most leaves in an m-ary tree of height h.
Remark: a full m-ary balanced tree of height h has more than leaves. Corollary1: if an m-ary tree of height has L leaves then If the m-ary tree is full and balanced then Remarks: 1) [x] is the smallest integer greater than or equal to x. 2) Graph containing no simple circuits that are not connected is called forests. Example of a forest.


Download ppt "Section10.1: Introduction to Trees"

Similar presentations


Ads by Google