Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 10 Trees Slides are adopted from “Discrete.

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.
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.
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.
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.
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
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.
Binary Trees. Binary Tree Finite (possibly empty) collection of elements A nonempty binary tree has a root element The remaining elements (if any) are.
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.
Agenda Review: –Planar Graphs Lecture Content:  Concepts of Trees  Spanning Trees  Binary Trees Exercise.
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.
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.
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.
Section10.1: Introduction to Trees
Applied Discrete Mathematics Week 14: Trees
Applied Discrete Mathematics Week 15: Trees
Graph Graphs and graph theory can be used to model:
Discrete Mathematicsq
Trees Chapter 11.
Data Structures and Algorithms
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
12. Graphs and Trees 2 Summary
Binary Trees "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb.
Introduction to Trees Section 11.1.
Trees.
Discrete Mathematics – CIS166
Trees L Al-zaid Math1101.
Lecture 36 Section 12.2 Mon, Apr 23, 2007
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…
Trees Chapter 11.
Presentation transcript:

Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 10 Trees Slides are adopted from “Discrete Mathematics and It's Applications” Kenneth H. Rosen; 6th edition, 2007.

Trees In this chapter we will focus on a particular type of graph called a tree, so named because such graphs resemble trees. For example, family trees are graphs that represent genealogical charts. Definition: A tree is a connected undirected graph with No simple circuits No multiple edges No loops

Trees Theorem: An undirected graph is a tree if and only if there is a unique simple path between any two of its vertices. Example: Which graphs are trees? G1 G2 G3 G4 Solution: G1 and G2 are trees, because both are connected graphs with no simple circuits. G3 is not a tree because e, b, a, d, e is a simple circuit in this graph. Finally, G4 is not a tree because it is not connected. a b a b a b a b c d d c e f e f e f e f

Trees Notes: Any connected graph that contains no simple circuits is a tree. Because a tree cannot have a simple circuit, a tree cannot contain multiple edges or loops. Therefore any tree must be a simple graph. What if there are no simple circuits but the graph is not connected? Each of the connected components is a tree. The collection is called a forest.

Trees 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. Rooted trees can also be defined recursively. We can change an unrooted tree into a rooted tree by choosing any vertex as the root. Note that different choices of the root produce different rooted trees. For instance, next figure displays the rooted trees formed by designating a to be the root and c to be the root, respectively, in the tree T. We usually draw a rooted tree with its root at the top of the graph.

A Tree and Rooted Trees Formed by Designating Two Roots. With root a With root c T a f g c d c d f g e f g c

Trees Example: Root a b c d e f a b c d e f a b c d e f

What if a different root is chosen? Trees What if a different root is chosen? Root a b c d e f a b c d e f a b c d e f a b c d e f A different rooted tree results.

Tree Terminology Definitions: If v is a vertex of tree 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 the child of u. If two vertices share the same parent, then they are called siblings.

Tree Terminology Example: a b c d e f g h i j k l m Siblings

Tree Terminology Definitions: The ancestors of a vertex other than the root are the vertices in the path from the root to this vertex, excluding the vertex itself and including the root. The descendants of a vertex v are those vertices that have v as an ancestor.

Example: Ancestors of k Tree Terminology Example: Ancestors of k a b c d e f g h i j k l m

Example: Descendants of d Tree Terminology Example: Descendants of d a b c d e f g h i j k l m

Tree Terminology Definitions: A vertex with no children is called a leaf. Vertices with children are called internal vertices. Example: Leaves a b c d e f g h i j k l m

Example: Internal vertices Tree Terminology Example: Internal vertices a b c d e f g h i j k l m

Tree Terminology Definition: If a is a vertex in a tree, the subtree with a as its root is: the subgraph of the tree consisting of a and its descendants, and all edges incident to these descendants.

Tree Terminology Example: Subtree at b Subtree at d a b c d e f g h i j k l m Subtree at d

Tree Terminology Definitions: A rooted tree is called an m-ary tree if every internal vertex has no more than m children. A 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.

Tree Terminology Example: What is the arity of this tree? Is this a full m-ary tree? ------------------- This is a 2-ary, or binary, tree. Yes, this is a full binary tree, since every internal vertex has exactly 2 children.

Tree Terminology Example: What is the arity of this tree? Is this a full m-ary tree? -------- This is a 3-ary tree. Yes, this is a full 3-ary tree, since every internal vertex has exactly 3 children.

Tree Terminology Example: What is the arity of this tree? Is this a full m-ary tree? ------- This is a full 5-ary tree.

Tree Terminology Example: What is the arity of this tree? Is this a full m-ary tree? Some internal nodes have 2 children, but some have 3, so this is a 3-ary tree. It is not a full-3-ary tree, since one internal node has only 2 children.

Ordered Rooted Tree Definitions: An ordered rooted tree is one where the children of each internal vertex are ordered. In an ordered binary tree, if an internal vertex has two children, then they are called left child and right child. The subtree rooted at the left child of a vertex is called the left subtree and subtree rooted at the right child of a vertex is called the right subtree.

Example: Left child of d Ordered Rooted Tree Example: Left child of d a b c d e h i f g j k l m

Ordered Rooted Tree Example: Right child of d a b c d e h i f g j k l

Ordered Rooted Tree Example: Left subtree of c a b c d e h i f g j k l

Ordered Rooted Tree Example: Right subtree of c a b c d e h i f g j k l m Right subtree of c

Tree Terminology Definitions: The level of a vertex v in a rooted tree is the length of the unique path from the root to this vertex. What is the level of the root? 0 The height of a rooted tree is the maximum of the levels of the vertices.

Tree Terminology Example: Levels 1 2 3 Height = 3 a b c d e f g h i j k l m 1 2 3 Height = 3

Tree Terminology Properties of Trees: A tree with n vertices has n1 edges. An full m-ary tree with i internal vertices contains n = mi + 1 vertices. A rooted m-ary tree of height h is called balanced if all leaves are at levels h or h–1

Tree Terminology Example: Find the level of each vertex in the rooted tree shown in the next figure . What is the height of this tree? Solution: The root a is at level O. Vertices b, j, and k are at level 1 . Vertices c, e, f, and I are at level 2. Vertices d, g, i , m , and n are at level 3 . Finally, vertex h is at level 4. Because the largest level of any vertex is 4, this tree has height 4. Note: A rooted m -ary tree of height h is balanced if all leaves are at levels h or h - 1 a h

Example: Is this tree balanced? Tree Terminology Example: Is this tree balanced?

Example: Is this tree balanced? Tree Terminology Example: Is this tree balanced?

Homework Pages 693 Exercises : 1, 2, 3, 4