Friday, March 30. Last time we were talking about traversal of a rooted ordered tree, having defined preorder traversal. We will continue from there.

Similar documents
7.1 Introduction. A (free) tree T is A simple graph such that for every pair of vertices v and w there is a unique path from v to w

Section 5.5. Left subtree The left subtree of a vertex V on a binary tree is the graph formed by the left child L of V, the descendents

Section Summary. Introduction to Trees Rooted Trees Trees as Models Properties of Trees

March 20/2003 Jayakanth Srinivasan,

Chapter 4 Trees. Theorem A graph G has a spanning tree if and only if G is connected.

Chapter Summary. Introduction to Trees Applications of Trees Tree Traversal Spanning Trees Minimum Spanning Trees

3. According to universal addressing, what is the address of vertex d? 4. According to universal addressing, what is the address of vertex f?

F453 Module 7: Programming Techniques. 7.2: Methods for defining syntax

TREES. Trees - Introduction

CSE 373 APRIL 17 TH TREE BALANCE AND AVL

Introduction to Computers and Programming. Concept Question

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

Binary Trees, Binary Search Trees

CS204 Discrete Mathematics. 11 Trees. 11 Trees

Chapter 10: Trees. A tree is a connected simple undirected graph with no simple circuits.

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.

Binary Trees


CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false.

CMSC th Lecture: Graph Theory: Trees.

There are many other applications like constructing the expression tree from the postorder expression. I leave you with an idea as how to do it.

Trees! Ellen Walker! CPSC 201 Data Structures! Hiram College!

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

syntax tree - * * * * * *

ASTS, GRAMMARS, PARSING, TREE TRAVERSALS. Lecture 14 CS2110 Fall 2018

Data Structures and Algorithms for Engineers

First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

Associate Professor Dr. Raed Ibraheem Hamed

12 Abstract Data Types

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Warm Up. Use Kruskal s algorithm to find the minimum spanning tree and it s weight.

License. Discrete Mathematics. Tree. Topics. Definition tree: connected graph with no cycle. examples. c T. Uyar, A. Yayımlı, E.

Chapter 20: Binary Trees

CSI33 Data Structures

Table of Contents. Chapter 1: Introduction to Data Structures... 1

COMP 250 Fall binary trees Oct. 27, 2017

Definition Example Solution

Data Structures. Trees. By Dr. Mohammad Ali H. Eljinini. M.A. Eljinini, PhD

DYNAMIC MEMORY ALLOCATION AND DEALLOCATION

Advanced Tree Data Structures

Discrete Mathematics. Chapter 7. trees Sanguk Noh

CSI33 Data Structures

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

syntax tree - * * * - * * * * * 2 1 * * 2 * (2 * 1) - (1 + 0)

Topics. Trees Vojislav Kecman. Which graphs are trees? Terminology. Terminology Trees as Models Some Tree Theorems Applications of Trees CMSC 302

Lecture Notes 16 - Trees CSS 501 Data Structures and Object-Oriented Programming Professor Clark F. Olson

Stacks, Queues and Hierarchical Collections

Trees. T.U. Cluj-Napoca -DSA Lecture 2 - M. Joldos 1

Graphs V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

CE 221 Data Structures and Algorithms

Upcoming ACM Events Linux Crash Course Date: Time: Location: Weekly Crack the Coding Interview Date:

CSE 230 Intermediate Programming in C and C++ Binary Tree

Trees. Trees. CSE 2011 Winter 2007

Trees Algorhyme by Radia Perlman

Algorithms and Data Structures (INF1) Lecture 8/15 Hua Lu

CS350: Data Structures Tree Traversal

Stacks, Queues and Hierarchical Collections. 2501ICT Logan

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))

Trees. Tree Structure Binary Tree Tree Traversals

Trees. Truong Tuan Anh CSE-HCMUT

COSC 2011 Section N. Trees: Terminology and Basic Properties

CSE 373 OCTOBER 11 TH TRAVERSALS AND AVL

Visit ::: Original Website For Placement Papers. ::: Data Structure

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.

Topic Binary Trees (Non-Linear Data Structures)

Friday Four Square! 4:15PM, Outside Gates

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

CSC148 Week 6. Larry Zhang

Tree Structures. A hierarchical data structure whose point of entry is the root node

Formal Languages and Automata Theory, SS Project (due Week 14)

Trees. CSE 373 Data Structures

Math 15 - Spring Homework 5.2 Solutions

Programming II (CS300)

Building Compilers with Phoenix

ADTS, GRAMMARS, PARSING, TREE TRAVERSALS

Programming II (CS300)

BACKGROUND: A BRIEF INTRODUCTION TO GRAPH THEORY

CS 206 Introduction to Computer Science II

Name CPTR246 Spring '17 (100 total points) Exam 3

Binary Trees. College of Computing & Information Technology King Abdulaziz University. CPCS-204 Data Structures I

LECTURE 13 BINARY TREES

Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

Data Structures - Binary Trees and Operations on Binary Trees

NANYANG TECHNOLOGICAL UNIVERSITY SEMESTER II EXAMINATION MH 1301 DISCRETE MATHEMATICS TIME ALLOWED: 2 HOURS

CSC148-Section:L0301

Finish Lec12 TREES, PART 2. Announcements. JavaHyperText topics. Trees, re-implemented. Iterate through data structure 3/7/19

Trees Rooted Trees Spanning trees and Shortest Paths. 12. Graphs and Trees 2. Aaron Tan November 2017

ADTS, GRAMMARS, PARSING, TREE TRAVERSALS

Graphs Introduction and Depth first algorithm

CHAPTER 10 GRAPHS AND TREES. Alessandro Artale UniBZ - artale/

Binary Search Trees. See Section 11.1 of the text.

CONTENTS Equivalence Classes Partition Intersection of Equivalence Relations Example Example Isomorphis

Tree Data Structures CSC 221

13 BINARY TREES DATA STRUCTURES AND ALGORITHMS INORDER, PREORDER, POSTORDER TRAVERSALS

([1-9] 1[0-2]):[0-5][0-9](AM PM)? What does the above match? Matches clock time, may or may not be told if it is AM or PM.

CSCI2100B Data Structures Trees

Binary Trees and Binary Search Trees

CS 151. Binary Trees. Friday, October 5, 12

Transcription:

Friday, March 30 Last time we were talking about traversal of a rooted ordered tree, having defined preorder traversal. We will continue from there.

Postorder traversal (recursive definition) If T consists only of r, then r is in the postorder traversal of T. Otherwise, let T 1, T 2, T n, be the subtrees at r from left to right. The preorder traversal begins by traversing T 1 in postorder, then T 2 in postorder, and so on, until T n has been traversed in postorder,, and ends by visiting r. That is, the root of a tree/subtree is visited after all the vertices of its subtrees are visited. Each subtree is traversed by traversing its subtrees from left to right, and then visiting its root.

Write the postorder traversal for this ordered tree.

Inorder traversal If T consists only of r, then r is in the inorder traversal of T. Otherwise, let T 1, T 2, T n, be the subtrees at r from left to right. The inorder traversal begins by traversing T 1 in inorder, then visiting r, then traversing T 2 in inorder, and so on, until T n has been traversed in inorder. That is, the root of a tree/subtree is visited after all the vertices of its left subtree are visited, but before the vertices of its other subtrees are visited. Each subtree is traversed by first traversing its left subtree, then visiting its root, then traversing its other subtrees from left to right.

Prefix notation, postfix notation Consider the algebraic expression x y/2 x 3 y When we write such an expression, we naturally include the bracketing symbols, such as parentheses, for purposes of clarity and to avoid the ambiguity that may result if we omit such symbols. Without such grouping symbols, the reader might not understand that we were trying to represent this operation: ( x y)/(2x 3y) Prefix (aka Polish) notation and postfix (aka reverse Polish) notation are two methods for representing an algebraic expression in a manner that does not require bracketing symbols, and which is unambiguous. Both prefix and postfix notation can be derived from the binary tree that represents the operation. Prefix notation is derived by preorder traversal; postfix notation is derived by postorder traversal.

EXAMPLE Draw the binary tree for z y representations. ( ) / ( 5 + (7z 3y) ) and use it to write the prefix and postfix

SPANNING TREES Definition Let G be a connected simple graph and let T be a subgraph of G. T is a spanning tree of G if T is a tree containing every vertex of G. Typically, a graph will have many possible spanning trees. One way to derive a spanning tree is to successively delete edges from G in a way that removes all cycles, but does not disconnect G.

EXAMPLE Find a spanning tree for this graph, by deleting edges until all cycles have been removed.

Depth-first search, breadth-first search Depth-first search and breadth-first search are two systematic methods for construction of a spanning tree. Both of these algorithms begin with the arbitrary selection of a vertex to serve as the root of the spanning tree. Depth first search After selecting a vertex to serve as the root, form a path starting at this root and successively adding vertices and edges, in such a way that each new edge of the path is incident with the last vertex in the path, and with another vertex not already in the path. If we are able to construct such a path that uses every vertex, then that path is the spanning tree. If the path does not use every vertex, then more vertices and edges need to be added. Move back to the next to the last vertex of the path, and, if possible, form a new path starting at this vertex, passing through vertices that were not already visited. If this cannot be done, move back another vertex in the path, and try again. Repeat this procedure, always backtracking from the last vertex visited, forming new paths that are as long as possible until no more edges can be added.

Referring to the graph in the previous example, use depth-first search to find a spanning tree rooted at a, then use depth-first search to find a spanning tree rooted at g.

Breadth-first search Again, begin by arbitrarily selecting a vertex to serve as the root. Next, add all edges incident to this root. These are the Level 1 vertices. Next, for each vertex added at Level 1, visited in order, add each edge incident to that vertex, so long as it does not produce a simple circuit. Now, arbitrarily order the children of each vertex added at Level 1; these are the vertices of Level 2. Visit, in order, each Level 2 vertex, adding every incident edge. Repeat the procedure as needed, expanding to new levels, until all vertices of G have been added to the tree.

Referring to the graph in the previous example, use breadth-first search to find a spanning tree rooted at a, then use breadth-first search to find a spanning tree rooted at d.