Chapter 11 1. Chapter Summary Introduction to Trees Applications of Trees (not currently included in overheads) Tree Traversal Spanning Trees Minimum.

Slides:



Advertisements
Similar presentations
Chapter 10, Section 10.3 Tree Traversal
Advertisements

Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
TREES Chapter 6. Trees - Introduction  All previous data organizations we've studied are linear—each element can have only one predecessor and successor.
1 Tree Traversal Section 9.3 Longin Jan Latecki Temple University Based on slides by Paul Tymann, Andrew Watkins, and J. van Helden.
Discrete Structures Lecture 13: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
CS 171: Introduction to Computer Science II
Chapter 4: Trees General Tree Concepts Binary Trees Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A12 – Binary Trees.
Tree Traversal. Traversal Algorithms preorder inorder postorder.
4/17/2017 Section 9.3 Tree Traversal ch9.3.
Unit 11a 1 Unit 11: Data Structures & Complexity H We discuss in this unit Graphs and trees Binary search trees Hashing functions Recursive sorting: quicksort,
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A12 – Binary Trees.
Binary Tree Properties & Representation. Minimum Number Of Nodes Minimum number of nodes in a binary tree whose height is h. At least one node at each.
1 CS308 Data Structures An application of binary trees: Binary Expression Trees.
Tree Traversal. Traversal Algorithms preorder inorder postorder.
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE The trees.
Binary Trees. Node structure Data A data field and two pointers, left and right.
Computer Science 112 Fundamentals of Programming II Expression Trees.
Trees Chapter 8. 2 Tree Terminology A tree consists of a collection of elements or nodes, organized hierarchically. The node at the top of a tree is called.
10.3 Tree Transversal. Pre/post fix notation and order See handout. a.bc.d e f g h i j k.
ساختمانهای گسسته دانشگاه صنعتی شاهرود – اردیبهشت 1392.
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.
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.
Data Structures : Project 5 Data Structures Project 5 – Expression Trees and Code Generation.
Searching Trees – Page 1CSCI 1900 – Discrete Structures CSCI 1900 Discrete Structures Searching Trees Reading: Kolman, Section 7.3.
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.
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.
Tree Data Structures.
Trees Chapter 8. 2 Tree Terminology A tree consists of a collection of elements or nodes, organized hierarchically. The node at the top of a tree is called.
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.
Prefix, Postfix and Infix. Infix notation  A-B/(C+D)  evaluate C+D (call the result X),  then B/X (call the result Y),  and finally A-Y.  The order.
Trees 2: Section 4.2 and 4.3 Binary trees. Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children
Tree Traversals, TreeSort 20 February Expression Tree Leaves are operands Interior nodes are operators A binary tree to represent (A - B) + C.
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.
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.
© University of Auckland Trees – (cont.) CS 220 Data Structures & Algorithms Dr. Ian Watson.
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.
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.
Data Structures Azhar Maqsood School of Electrical Engineering and Computer Sciences (SEECS-NUST) Binary Trees.
Graphs and Trees Mathematical Structures for Computer Science Chapter 5 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesGraphs and Trees.
Chapter 7 Trees_ Part2 TREES. Depth and Height 2  Let v be a node of a tree T. The depth of v is the number of ancestors of v, excluding v itself. 
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 Applications of Trees (not currently included in overheads) Tree Traversal Spanning Trees Minimum Spanning.
Discrete Mathematics Trees.
Trees Chapter 15.
Recursive Objects (Part 4)
Trees Chapter 11.
Paul Tymann and Andrew Watkins
Trees Another Abstract Data Type (ADT)
Section 8.1 Trees.
Binary Tree Traversal Methods
Binary Tree Traversal Methods
Paul Tymann, Andrew Watkins,
Principles of Computing – UFCFA3-30-1
Binary Tree Traversal Methods
Section 9.3 by Andrew Watkins
Paul Tymann, Andrew Watkins,
Binary Tree Properties & Representation
Chapter 20: Binary Trees.
Binary Tree Traversal Methods
Trees Chapter 11.
Binary Tree Traversal.
8.2 Tree Traversals Chapter 8 - Trees.
Presentation transcript:

Chapter 11 1

Chapter Summary Introduction to Trees Applications of Trees (not currently included in overheads) Tree Traversal Spanning Trees Minimum Spanning Trees (not currently included in overheads) 2

Section

Section

Section Summary Universal Address Systems (not currently included in overheads) Traversal Algorithms Infix, Prefix, and Postfix Notation 5

Tree Traversal Procedures for systematically visiting every vertex of an ordered tree are called traversals. The three most commonly used traversals are preorder traversal, inorder traversal, and postorder traversal. 6

Preorder Traversal Definition: Let T be an ordered rooted tree with root r. If T consists only of r, then r is the preorder traversal of T. Otherwise, suppose that T 1, T 2, …, T n are the subtrees of r from left to right in T. The preorder traversal begins by visiting r, and continues by traversing T 1 in preorder, then T 2 in preorder, and so on, until T n is traversed in preorder. 7

Preorder Traversal (continued) procedure preorder (T: ordered rooted tree) r := root of T list r for each child c of r from left to right T(c) := subtree with c as root preorder(T(c)) 8

Inorder Traversal Definition: Let T be an ordered rooted tree with root r. If T consists only of r, then r is the inorder traversal of T. Otherwise, suppose that T 1, T 2, …, T n are the subtrees of r from left to right in T. The inorder traversal begins by traversing T 1 in inorder, then visiting r, and continues by traversing T 2 in inorder, and so on, until T n is traversed in inorder. 9

Inorder Traversal (continued) procedure inorder (T: ordered rooted tree) r := root of T if r is a leaf then list r else l := first child of r from left to right T(l) := subtree with l as its root inorder(T(l)) list(r) for each child c of r from left to right T(c) := subtree with c as root inorder(T(c)) 10

Postorder Traversal Definition: Let T be an ordered rooted tree with root r. If T consists only of r, then r is the postorder traversal of T. Otherwise, suppose that T 1, T 2, …, T n are the subtrees of r from left to right in T. The postorder traversal begins by traversing T 1 in postorder, then T 2 in postorder, and so on, after T n is traversed in postorder, r is visited. 11

Postorder Traversal (continued) procedure postordered (T: ordered rooted tree) r := root of T for each child c of r from left to right T(c) := subtree with c as root postorder(T(c)) list r 12

Expression Trees Complex expressions can be represented using ordered rooted trees. Consider the expression ((x + y) ↑ 2 ) + ((x − 4 )/ 3 ). A binary tree for the expression can be built from the bottom up, as is illustrated here. 13

Infix Notation An inorder traversal of the tree representing an expression produces the original expression when parentheses are included except for unary operations, which now immediately follow their operands. We illustrate why parentheses are needed with an example that displays three trees all yield the same infix representation. 14

Prefix Notation When we traverse the rooted tree representation of an expression in preorder, we obtain the prefix form of the expression. Expressions in prefix form are said to be in Polish notation, named after the Polish logician Jan Ł ukasiewicz. Operators precede their operands in the prefix form of an expression. Parentheses are not needed as the representation is unambiguous. The prefix form of ((x + y) ↑ 2 ) + ((x − 4 )/ 3 ) is + ↑ + x y 2 / − x 4 3. Prefix expressions are evaluated by working from right to left. When we encounter an operator, we perform the corresponding operation with the two operations to the right. Example: We show the steps used to evaluate a particular prefix expression: Jan Ł ukasiewicz ( ) 15

Postfix Notation We obtain the postfix form of an expression by traversing its binary trees in postorder. Expressions written in postfix form are said to be in reverse Polish notation. Parentheses are not needed as the postfix form is unambiguous. x y + 2 ↑ x 4 − 3 / + is the postfix form of ((x + y) ↑ 2 ) + ((x − 4 )/ 3 ). A binary operator follows its two operands. So, to evaluate an expression one works from left to right, carrying out an operation represented by an operator on its preceding operands. Example: We show the steps used to evaluate a particular postfix expression. 16