Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.

Slides:



Advertisements
Similar presentations
Trees Chapter 11.
Advertisements

Chapter 9 Graphs.
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 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.
Binary Tree Terminology Linear versus hierarchical data Tree – connected graph with no cycles Child Parent Descendant Sibling Ancestor Leaf vs. internal.
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.
4/17/2017 Section 9.3 Tree Traversal ch9.3.
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.
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
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.
Trees CSC 172 SPRING 2002 LECTURE 14. Lists We have seen lists: public class Node { Object data; Node next; } 
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 2 Overview Trees. Terminology. Traversal of Binary Trees. Expression Trees. Binary Search Trees.
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.
Tree (new ADT) Terminology:  A tree is a collection of elements (nodes)  Each node may have 0 or more successors (called children)  How many does a.
Lecture 8 Tree.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
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.
TREES. What is a tree ? An Abstract Data Type which emulates a tree structure with a set of linked nodes The nodes within a tree are organized in a hierarchical.
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.
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.
1 Trees 2 Binary trees Section Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children –Left and.
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.
Hello Everyone!!! 1. Tree And Graphs 2 Features of Trees  Tree Nodes Each node have 0 or more children A node have must one parent  Binary tree Tree.
Graphs and Trees Mathematical Structures for Computer Science Chapter 5 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesGraphs and Trees.
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.
1 Trees. 2 Trees Trees. Binary Trees Tree Traversal.
Section10.1: Introduction to Trees
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
CSCE 210 Data Structures and Algorithms
Trees Chapter 11.
Paul Tymann and Andrew Watkins
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
Trees Another Abstract Data Type (ADT)
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.
Section 8.1 Trees.
Binary Trees, Binary Search Trees
CS223 Advanced Data Structures and Algorithms
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 10 Trees Slides are adopted from “Discrete.
Trees Another Abstract Data Type (ADT)
Trees Definitions Implementation Traversals K-ary Trees
Trees Another Abstract Data Type (ADT)
Discrete Mathematics – CIS166
Trees L Al-zaid Math1101.
Section 9.3 by Andrew Watkins
Binary Trees, Binary Search Trees
Discrete Mathematics – CIS166
Trees 11.1 Introduction to Trees Dr. Halimah Alshehri.
Trees Chapter 11.
Binary Trees, Binary Search Trees
Presentation transcript:

Chapter 10: Trees

Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.

Theorem 1. An undirected graph is a tree iff there is a unique simple path between any two vertices. 2. A simple graph G = (V, E) is a tree iff |E| = |V| - 1

Definition A rooted tree is a tree in which one vertex is specified as the root & every edge is drawn away from the root  root

Definition root vertex parent children Level 0 Level 1 Level 2 Level 3 Height=3

Definition Root: a vertex with no parent Leaf: a vertex with no children Internal node: vertex with children Descendants: all children and children of children Ancestors: parent and parents of parents Siblings: vertices with the same parent Height = number of levels - 1

Definition An m-ary tree is a rooted tree where the number of children of any internal vertex  m A full m-ary tree is an m-ary tree where the number of children of any internal vertex = m if m=2, we call it binary tree

Full 3-ary tree 3-ary tree

Definition In an ordered rooted tree the children are ordered. For example, in an ordered binary tree, a vertex may have left child and right child Left child Right child Left childRight child root

Properties Any tree of size n has n-1 edges Any full m-ary tree with i internal vertices has m i + 1 vertices Any m-ary tree with height h has at most m h leaves.

Properties A full m-ary tree with n vertices has i =(n-1)/m internal and l = ((m-1)n+1)/m leaves. Notice that n=l+i i internal 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

Section 10.3 Tree Traversal

Tree Traversal Away for visiting ordered rooted trees

Pre-order Visit x, T1 in preorder, T2 in preorder, T3 in preorder....and so on x T1 T4T2 T3

In-order Visit T1 in inorder, x, T2 in inorder, T3 in inorder....and so on x T1 T4T2 T3

Post-order Visit T1 in post-order, T2 in post-order, T3 in post-order.... etc, and then x. x T1 T4T2 T3

Example Pre-order: a, b, e, f, g, h, i, j, c, d In-order: e, b, f, h, g, i, j, a, c, d Post-order: e, f, h, i, j, g, b, c, d, a a b c d e f g h i j

Tree that represents expressions Any arithmetic expression can be represented by a rooted tree (x+1)^2-(3/2) x ^/ -

Ambiguous expressions x + y * z = (x + y) * z ? = x + (y * z) ? Parentheses have to be used to avoid ambiguity

Infix, prefix, & postfix Any arithmetic expression can be written in an unambiguous form Prefix form: an pre-order traversal of the expression’s rooted tree Infix form: an in-order traversal of the expression’s rooted tree Postfix form: an post-order traversal of the expression’s rooted tree

Example Consider the expression (x+1)^2-(3/2) Infix form: x+1^2-3/2 Prefix: -^+x12/32 Postfix: x1+2^32/- x ^/ -