Discrete Mathematics Transparency No. 8-1 Chapter 8 Trees.

Slides:



Advertisements
Similar presentations
Chapter 11 Trees Graphs III (Trees, MSTs) Reading: Epp Chp 11.5, 11.6.
Advertisements

Trees Chapter 11.
Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
Graphs III (Trees, MSTs) (Chp 11.5, 11.6)
CMPS 2433 Discrete Structures Chapter 5 - Trees R. HALVERSON – MIDWESTERN STATE UNIVERSITY.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
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
CS 171: Introduction to Computer Science II
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.
Rooted Trees. More definitions parent of d child of c sibling of d ancestor of d descendants of g leaf internal vertex subtree root.
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.
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.
Graph Algorithms Using Depth First Search Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
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.
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
LOGO.  Trees:  In these slides: Introduction to trees Applications of trees Tree traversal 2.
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.
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.
CSCI 115 Chapter 7 Trees. CSCI 115 §7.1 Trees §7.1 – Trees TREE –Let T be a relation on a set A. T is a tree if there exists a vertex v 0 in A s.t. there.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Lecture 8 Tree.
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.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
Trees Dr. B. Prabhakaran Application Examples Useful for locating items in a list Used in Huffman coding algorithm Study games like.
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 By P.Naga Srinivasu M.tech,(MBA). Basic Tree Concepts A tree consists of finite set of elements, called nodes, and a finite set of directed lines.
Discrete Mathematics Chapter 5 Trees.
CS 103 Discrete Structures Lecture 23 Trees (1). Second Midterm Exam 1 st Lecture in December (same time as the lecture) 75 minute duration Will cover.
1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.
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.
Discrete Structures – CNS 2300 Text Discrete Mathematics and Its Applications (5 th Edition) Kenneth H. Rosen Chapter 9 Trees.
Discrete Mathematics Chapter 10 Trees. Outline 10.1 Introduction to Trees 10.2 Applications of Trees 10.3 Tree Traversal 10.4 Spanning Trees 10.5 Minimal.
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.
1 Trees. 2 Trees Trees. Binary Trees Tree Traversal.
Section10.1: Introduction to Trees
Discrete Mathematics Trees.
Applied Discrete Mathematics Week 15: Trees
CSCE 210 Data Structures and Algorithms
Discrete Mathematicsq
Trees Chapter 11.
12. Graphs and Trees 2 Summary
Introduction to Trees Section 11.1.
Binary Trees, Binary Search Trees
Graph Algorithms Using Depth First Search
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
Binary Trees, Binary Search Trees
Discrete Mathematics – CIS166
Trees 11.1 Introduction to Trees Dr. Halimah Alshehri.
And the Final Subject is…
Trees Chapter 11.
Binary Trees, Binary Search Trees
Presentation transcript:

Discrete Mathematics Transparency No. 8-1 Chapter 8 Trees

Discrete Mathematics Ch 4 Trees Transparency No. 8-2 contents Introduction definitions properties of trees Applications binary search trees Decision trees Prefix codes Tree traversal universal address systems inorder, preorder and postorder traversal infix, prefix and postfix notation – linearize(serialize) trees. trees and sorting -- bubble sort, merge-sort spanning trees minimum spanning trees -- Prim's alg; Kruskal's alg.

Discrete Mathematics Ch 4 Trees Transparency No Introduction A connected graph w/o simple circuits useful in CS and many fields Def1: A tree is a connected undirected graph w/o simple circuits (cf: Forest) Ex1: Family Tree: Ex2: x y ==> X is the parent of Y tree has cyclenot connected

Discrete Mathematics Ch 4 Trees Transparency No. 8-4 Theorem 1: Theorm1:An undirected graph is a tree iff there is a unique simple path b/t any two of its vertices. Pf:”=>”: T: any tree; x,y: two distinct vertices. Since T is connected, by def., there is a path and hence a simple path  from x to y. Assume there is another simple path  from x to y. Then by a theorem of ch 7 about simple circuit, there is a simple circuit in T.=> T is not a tree, a contradiction! “ T is connected. Assume T contains a simple cycle containing x and y. (i.e., x --  -- y --  -- x ==> T contains two simple paths from x to y, a contradiction.

Discrete Mathematics Ch 4 Trees Transparency No. 8-5 Rooted Tree A rooted tree is a tree T=(V,E) associated with a distinguished vertex r ∈ V called the root of T. Given a rooted tree with root r, we can form a directed graph with the property that (u,v) ∈ V 2 is an edge of the new directed graph iff u appears immediately before v in the unique simple path from the root r to v.

Discrete Mathematics Ch 4 Trees Transparency No. 8-6 A tree and Rooted Tree formed by designating two roots a b c d e f g T a b c d e f g With root c a b c d e f g With root a

Discrete Mathematics Ch 4 Trees Transparency No. 8-7 Some terminology of rooted tree T= : a rooted tree. The associated digraph of T is a digraph G T = (V,E’) where E’ = {(u,v) ∈ V 2 |{u,v} ∈ E and ∃ a path r---….---u---v in T} if (u,v) ∈ E’ => u is called the parent of v (and v a child of u) Vertices with the same parent are called siblings. All vertices(except v) in the unique path from the root r to a vertex v are ancestors of v. v is a descendant of u iff u is an ancestor of v. Vertices without children are called leaves Vertices having children are called internal nodes.

Discrete Mathematics Ch 4 Trees Transparency No. 8-8 subtrees T=(V,E,r): a rooted tree; a: a vertex. The subtree of T with a as root is the tree T’=(V’,E’,a) where V’ = {{a} U {v | v is a descendant of a} E’ = E| V’ (E restricted to V’) = { {u,v} ∈ E | {u,v} ⊆ V’ } Example: root internal nodes leaves parent, child sibling ancestor, descendant a b c d e f g

Discrete Mathematics Ch 4 Trees Transparency No. 8-9 m-ary tree Def: A rooted tree is an m-ary tree (m > 0) if every internal vertex has no more than m children. A tree is a full m-ary tree if every internal vertex has exactly m children. A 2-ary tree is also called a binary tree. Ordered rooted tree: the children of each vertex are ordered. The first (second) child of a vertex in an ordered binary tree is called its left (right) child. The subtree rooted at the left [right] child of the root of an ordered binary tree is called its left [right] subtree.

Discrete Mathematics Ch 4 Trees Transparency No Example 4: left and right child of d = ? left and right subtree of c = ? Notes: 1. Like graphs, there is no standard terminology used to describe trees, rooted trees, ordered rooted trees and binary trees. 2. Readers should carefully check meanings given to terms dealing with trees whenever they occur. a b c d e f g h i j k l m

Discrete Mathematics Ch 4 Trees Transparency No Trees as models

Discrete Mathematics Ch 4 Trees Transparency No Properties of trees Theorem 2: A tree with n ( n >0) vertices has exactly n-1 edges. Pf: Let T = (V,E) be a tree and choose a vertex r as the root. Now define the mapping g: E  V- {r} by g(e) = v iff e={u,v} and v is the child of u. Obviously g is 1-1 and onto. Hence |E| = |V| : if e 1 = {u 1,v}, e 2 = {u 2,v} with g(e 1 ) = g(e 2 )=v => both u 1 and u 2 are the vertex appearing immediately before v in the unique simple path from r to v => u 1 = u 2. onto: v ∈ V – {r}, there is a unique simple path of length > 0 from r to v => there is a vertex u occurring immediately before v => g({u,v}) = v.

Discrete Mathematics Ch 4 Trees Transparency No Number of vertices in a complete m-ary tree Theorem 3: A full m-ary tree with i internal vertices contains n = mi + 1 vertices. Pf: Note: every edge in a tree T=(V,E,r) contributes one parent-degree and one child- degree. => the number of parent-degrees=  v ∈ V #children(v) [ = |E| = number of child-degrees =  v ∈ V #parent(v) = |V|-1 : another proof of theorem 2 ] =  v ∈ V-all leaves #children(v) --- leaves have no parent- degree. =  v ∈ V-all leaves m = mi every internal vertex has m children. => |V| = mi + 1.

Discrete Mathematics Ch 4 Trees Transparency No Theorem 4 T: a full m-ary tree with n vertices, i internal vertices and l leaves. Then 1. i = (n-1)/m and l = [(m-1)n+1]/m 2. n = mi +1 and l = (m-1) + i n = (ml-1) / (m-1) and i = (l-1)/(m-1). pf: All are simple results of the following equations: (1) n = mi + 1 (*, Theorem 3) and (2) n = l + i (every vertex is either a leaf or an internal vertex) 1: i = (n-1) /m and l = n - i =n – (n-1)/m =[(m-1)n+1]/m 2,3: Left as exercises.

Discrete Mathematics Ch 4 Trees Transparency No Example 9 Someone starts a chain letter. Each person receiving the letter either sends to 4 other people or stops sending letter. ==> 1.#people seeing the letter = ? if no one receiving the letter more than once and the chain letter ends after 100 people reading it but did not send it out. 2. #people sending out the letter = ? Sol: T=(V,E,r) where V = all people receiving (and seeing) the letter r = the person starting the game E = {(u,v) | u sends a letter to v }  #leaves = l = 100 =>  n = l + #internal vertices(i) and n = 4i + 1  n = l + (n-1) /4 => l = n – (n-1)/4 = (3n+1)/4 =100  n = 400 –1 /3 = 133. => i = n –l = 33.

Discrete Mathematics Ch 4 Trees Transparency No the Level of nodes and the height of a tree T=(V,E,r) : a tree, a: a vertex. Level(a) = depth(a) = the length of the unique path from root to a. Level(T) = height(T)= max v ∈ V level(v) Example 10: level(v) = ? for each vertex v in the tree? Height(T) = ? A m-ary tree is a complete tree if it is full and all leaves have the same height a b c d e f g h i j k l m

Discrete Mathematics Ch 4 Trees Transparency No Balanced trees A tree is balanced if the subtrees at each vertex have approximately the same height. Def: A rooted m-ary tree of height h is called balanced if all leaves are at levels h or h-1. Example 11: Which of the rooted trees are balanced ? T1 T2

Discrete Mathematics Ch 4 Trees Transparency No T3

Discrete Mathematics Ch 4 Trees Transparency No Maximum number of leaves in a tree. Theorem 5: There are at most m h leaves in an m-ary tree T of height h. Pf: By math ind on h. Basis: h = 0 => T has only 1 = m 0 node, which is a leaf. Ind. case: Assume every m-ary tree of height h has leaves ≤ m h => m-ary tree T of height h+1 has at most m subtrees, each of height h => #leaves(T) =  t’ is a subtree of T #leaves(T’) ≤ m x m h = m h+1. Theorem 5’ : Every complete m-ary tree of height h has m h leaves. Pf: Like Theorem 5.

Discrete Mathematics Ch 4 Trees Transparency No Corollary 1 Corollary If an m-ary tree of height h has l leaves, then h ≥ [log m l]. 2. If the m-ary tree is full and balanced, then h =[log m l], where [-] is the ceiling function. Pf:1. By Theorem 5, l ≤ m h ; hence h ≥ log m l. Since h is an integer, h ≥ [log m l]. 2. ∵ balanced => h-1 ≤ level of leaves ≤ h ∵ height = h => Some vertex is at level h. => m h-1 < l ≤ m h. => h< 1+ log m l and h ≥ log m l => log m l ≤ h < 1 + log m l => h = [log m l].