Section10.1: Introduction to Trees

Slides:



Advertisements
Similar presentations
Trees Chapter 11.
Advertisements

Chapter 9 Graphs.
Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
Introduction to Trees Chapter 6 Objectives
CMPS 2433 Discrete Structures Chapter 5 - Trees R. HALVERSON – MIDWESTERN STATE UNIVERSITY.
1 Chapter 10 Trees. Tree Definition 1. A tree is a connected undirected graph with no simple circuits. Theorem 1. An undirected graph is a tree if and.
1 Copyright M.R.K. Krishna Rao 2003 Ch 9 - Trees Definition: A tree is a connected undirected graph with no simple circuits. Since a tree cannot have a.
1 Section 9.1 Introduction to Trees. 2 Tree terminology Tree: a connected, undirected graph that contains no simple circuits –must be a simple graph:
Discrete Mathematics – CIS166
Discrete Mathematics Transparency No. 8-1 Chapter 8 Trees.
Section 3.1 Properties of Trees Sarah Graham. Tree Talk: Vocabulary oTree: a tree is a special type of graph that contains designated vertex called a.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
A tree is a simple graph satisfying: if v and w are vertices and there is a path from v to w, it is a unique simple path. a b c a b c.
Rooted Trees. More definitions parent of d child of c sibling of d ancestor of d descendants of g leaf internal vertex subtree root.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
MATH 310, FALL 2003 (Combinatorial Problem Solving) Lecture 11, Wednesday, September 24.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Trees.
03/01/2005Tucker, Sec Applied Combinatorics, 4th Ed. Alan Tucker Section 3.1 Properties of Trees Prepared by Joshua Schoenly and Kathleen McNamara.
CSC 2300 Data Structures & Algorithms February 6, 2007 Chapter 4. Trees.
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE The trees.
Trees and Tree Traversals Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Let G be a pseudograph with vertex set V, edge set E, and incidence mapping f. Let n be a positive integer. A path of length n between vertex v and vertex.
May 5, 2015Applied Discrete Mathematics Week 13: Boolean Algebra 1 Dijkstra’s Algorithm procedure Dijkstra(G: weighted connected simple graph with vertices.
CS261 Data Structures Trees Introduction and Applications.
Introduction Of Tree. Introduction A tree is a non-linear data structure in which items are arranged in sequence. It is used to represent hierarchical.
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
Introduction to Trees. When at a node in a singly linked list, there is no choice as to which node can be visited next: Motivation when here we can only.
Section 10.1 Introduction to Trees These class notes are based on material from our textbook, Discrete Mathematics and Its Applications, 6 th ed., by Kenneth.
May 1, 2002Applied Discrete Mathematics Week 13: Graphs and Trees 1News CSEMS Scholarships for CS and Math students (US citizens only) $3,125 per year.
Foundations of Discrete Mathematics
Tree A connected graph that contains no simple circuits is called a tree. Because a tree cannot have a simple circuit, a tree cannot contain multiple.
Copyright © Cengage Learning. All rights reserved. CHAPTER 10 GRAPHS AND TREES.
Module #19: Graph Theory: part II Rosen 5 th ed., chs. 8-9.
Discrete Structures Lecture 12: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
Trees – Chapter 9 Slides courtesy of Dr. Michael P. Frank University of Florida Dept. of Computer & Information Science & Engineering.
5.5.3 Rooted tree and binary tree  Definition 25: A directed graph is a directed tree if the graph is a tree in the underlying undirected graph.  Definition.
Discrete Structures Trees (Ch. 11)
Chap 8 Trees Def 1: A tree is a connected,undirected, graph with no simple circuits. Ex1. Theorem1: An undirected graph is a tree if and only if there.
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Discrete Mathematics Chapter 5 Trees.
1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.
Trees Dr. Yasir Ali. A graph is called a tree if, and only if, it is circuit-free and connected. A graph is called a forest if, and only if, it is circuit-free.
Chapter 10: Trees A tree is a connected simple undirected graph with no simple circuits. Properties: There is a unique simple path between any 2 of its.
Data Structures Lakshmish Ramaswamy. Tree Hierarchical data structure Several real-world systems have hierarchical concepts –Physical and biological systems.
CHAPTER 11 TREES INTRODUCTION TO TREES ► A tree is a connected undirected graph with no simple circuit. ► An undirected graph is a tree if and only.
1 Trees What is a Tree? Tree terminology Why trees? What is a general tree? Implementing trees Binary trees Binary tree implementation Application of Binary.
Discrete Structures – CNS 2300 Text Discrete Mathematics and Its Applications (5 th Edition) Kenneth H. Rosen Chapter 9 Trees.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
Discrete Mathematics Chapter 10 Trees.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Chapter 11. Chapter Summary Introduction to Trees Applications of Trees (not currently included in overheads) Tree Traversal Spanning Trees Minimum Spanning.
Tree Representation and Terminology Binary Trees Binary Search Trees Pointer-Based Representation of a Binary Tree Array-Based Representation of a Binary.
Applied Discrete Mathematics Week 15: Trees
Graph Graphs and graph theory can be used to model:
Discrete Mathematicsq
Trees Chapter 11.
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
12. Graphs and Trees 2 Summary
Introduction to Trees Section 11.1.
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 10 Trees Slides are adopted from “Discrete.
Discrete Mathematics – CIS166
Trees L Al-zaid Math1101.
Trees 11.1 Introduction to Trees Dr. Halimah Alshehri.
Discrete Mathematics – CIS166
Trees 11.1 Introduction to Trees Dr. Halimah Alshehri.
And the Final Subject is…
Presentation transcript:

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?

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:

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.

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

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.

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

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?

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.

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.

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.