Trees Chapter 9.

Slides:



Advertisements
Similar presentations
Trees Chapter 11.
Advertisements

Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Discrete Structures Lecture 13: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
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 Section 9.1 Introduction to Trees. 2 Tree terminology Tree: a connected, undirected graph that contains no simple circuits –must be a simple graph:
Binary Trees, Binary Search Trees COMP171 Fall 2006.
CS 171: Introduction to Computer Science II
Discrete Mathematics Transparency No. 8-1 Chapter 8 Trees.
Chapter 4: Trees General Tree Concepts Binary Trees Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
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.
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.
May 5, 2015Applied Discrete Mathematics Week 13: Boolean Algebra 1 Dijkstra’s Algorithm procedure Dijkstra(G: weighted connected simple graph with vertices.
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
LOGO.  Trees:  In these slides: Introduction to trees Applications of trees Tree traversal 2.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
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.
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.
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 Dr. B. Prabhakaran Application Examples Useful for locating items in a list Used in Huffman coding algorithm Study games like.
Preview  Graph  Tree Binary Tree Binary Search Tree Binary Search Tree Property Binary Search Tree functions  In-order walk  Pre-order walk  Post-order.
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.
Chapter 4: Trees Part I: General Tree Concepts Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
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.
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 General Trees  Nonrecursive definition: a tree consists of a set of nodes and a set of directed edges that connect pairs of nodes.
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.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
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.
Section10.1: Introduction to Trees
Discrete Mathematics Trees.
Applied Discrete Mathematics Week 15: Trees
Discrete Mathematicsq
Trees Chapter 11.
Paul Tymann and Andrew Watkins
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
12. Graphs and Trees 2 Summary
Tree.
Introduction to Trees Section 11.1.
Binary Trees, Binary Search Trees
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 10 Trees Slides are adopted from “Discrete.
Binary Trees, Binary Search Trees
Trees 11.1 Introduction to Trees Dr. Halimah Alshehri.
And the Final Subject is…
Binary Trees.
Trees Chapter 11.
Binary Trees, Binary Search Trees
A Binary Tree is a tree in which each node has at most 2 children
Presentation transcript:

Trees Chapter 9

Tree graph connected undirected no simple circuits (acyclic) no multiple edges no loops

Sample Trees? Tree Tree Not Not

Theorem 1 An undirected graph is a tree iff A simple path exists in a tree between any two vertices

Root A particular tree vertex Each edge is directed away from the root from which we assign a direction to each edge Each edge is directed away from the root

Rooted tree A tree with a designated root A directed graph Direction of all edges is away from root

Parent In a rooted tree, a parent of vertex v is the unique vertex u such that there is a directed edge from u to v

Child The vertex v to which a directed edge exists from parent u in a rooted tree

Siblings vertices with the same parent

Leaf a vertex of a tree that has no children

Ancestors of node A nodes located on the path from A to the root

Descendants of node A nodes located on the path from A to a leaf node

Internal vertices Vertices with children

Sub-tree a tree contained in a larger tree whose root may be a child node in the larger tree

m-ary tree a rooted tree with no more than m children per vertex

Full m-ary tree a rooted tree whose every internal vertex has exactly m children

Theorem 2 A tree with n vertices has n - 1 edges. 7 vertices 6 edges

Theorem 3 A full m-ary tree with i internal vertices contains n = mi + 1 vertices. m = 2 i = 7 15 vertices

Tree Height height (level) of a node height of a tree the length of the path from the root to a node height of a tree the length of the longest path in a tree

The maximum number of nodes at any level is mh h is height of a node at that level of the tree 212223

The minimum number of nodes of a tree of height h is h+1

The maximum number of nodes in a tree of height h is m(h+1) -1 2(3+1) - 1

Balanced tree A rooted m-ary tree of height h is called balanced if all leaves are at level h or h - 1 YES NO YES

If an m-ary tree of height h has l leaves, and the tree is full and balanced, h = ceil(log m l) h = ceil (log28) h = 3 What does this imply about access speed if a tree is used as a data structure?

Applications of Trees 8.2

Binary search tree A binary tree where key value in any node is greater than key of its left child and any of its children (the nodes in the left subtree) less than key of its right child (the nodes in the right subtree) http://math.nemcc.edu/bst/

Binary Search Tree Example

Form a BST with the words Mathematics, Physics, Geography, Zoology, Meteorology, Geology, Psychology, Chemistry

NOTE: Input order determines a tree's shape. Tree Animation

Tree Traversal 8.3

Inorder Tree Traversal process Left subtree inorder Visit a node (or process node) Process Right subtree inorder Processes BST vertices in ascending sequence http://nova.umuc.edu/~jarc/idsv/lesson1.html

Inorder Traversal Example LVR Arps, Dietz, Egofske, Fairchild, Garth, Huston, Keith Magillicuddy, Nathan, Perkins, Seliger, Talbot, Underwood,Verkins, Zarda

Preorder Tree Traversal allows quickest access to the whole tree VISIT a node process LEFT subtree in preorder process RIGHT subtree in preorder

Preorder Traversal Example VLR Magillicuddy, Fairchild, Dietz, Arps, Egofske, Huston, Garth, Keith, Talbot, Perkins, Nathan, Selinger, Verkins, Underwood, Zarda

Postorder Tree Traversal good for deletion of nodes; postfix notation process LEFT subtree in postorder process RIGHT subtree in postorder VISIT a node

Postorder Traversal Example LRV Arps, Egofske, Dietz, Garth, Keith, Huston, Fairchild, Nathan, Selinger, Perkinds, Underwood, Zarda, Verkins, Talbot, Magillicuddy

Expression Tree An ordered rooted tree associates operands & operators in a uniform way +

Give Pre, In, Postorder PreOrder: InOrder: PostOrder: - + + * 6 2 7 * 8 3 / 6 7 InOrder: 6 * 2 + 7 + 8 * 3 - 6 / 7 PostOrder: 6 2 * 7 + 8 3 * + 6 7 / - +

Spanning Trees 9.4

Spanning Subgraph A spanning subgraph of G is G’ = (V, E’) where E’ is a subset of E Note every vertex of G is included

Spanning Tree A spanning subgraph that is a tree connected acyclic See p. 581-2

Depth First Search A procedure for constructing a spanning tree by adding edges that form a path until this is not possible then moving back up the tree until a vertex is found where a new path can be formed http://www.cs.sunysb.edu/~skiena/combinatorica/animations/search.html

Breadth First Search A procedure for constructing a spanning tree that successively adds all edges incident to the last set of edges added unless a simple circuit is formed http://www.cs.duke.edu/~wcp/DFSanim.html http://152.3.140.5/~wcp/DFSanim.html

Perform DFS, BFS search DFS: a, b, c, d, e, f, g BFS: a b c g d e f

Perform DFS, BFS search DFS: a, b, c, d, e, f BFS: a b d e c f

Minimum Spanning Tree A connected weighted graph is a spanning tree that has the smallest possible sum of weights of its edges. http://study.haifa.ac.il/~hvaiderm/sem3.html