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

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

March 20/2003 Jayakanth Srinivasan,

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

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

TREES. Trees - Introduction

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

Binary Trees, Binary Search Trees

Introduction to Computers and Programming. Concept Question

Chapter 20: Binary Trees

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

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

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

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

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

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

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

CSI33 Data Structures

Trees. Trees. CSE 2011 Winter 2007

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


Binary Trees

Associate Professor Dr. Raed Ibraheem Hamed

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

CSI33 Data Structures

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

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

CE 221 Data Structures and Algorithms

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

Programming II (CS300)

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

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

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


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

12 Abstract Data Types

Tree. Virendra Singh Indian Institute of Science Bangalore Lecture 11. Courtesy: Prof. Sartaj Sahni. Sep 3,2010

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

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

CS 171: Introduction to Computer Science II. Binary Search Trees

Binary Trees and Binary Search Trees

LECTURE 13 BINARY TREES

Trees. (Trees) Data Structures and Programming Spring / 28

THE EULER TOUR TECHNIQUE: EVALUATION OF TREE FUNCTIONS

Trees. Truong Tuan Anh CSE-HCMUT

CSC148 Week 6. Larry Zhang

Data Structures and Algorithms for Engineers

Why Use Binary Trees? Data Structures - Binary Trees 1. Trees (Contd.) Trees

THE EULER TOUR TECHNIQUE: EVALUATION OF TREE FUNCTIONS

Data Structures - Binary Trees 1

Trees. Make Money Fast! Stock Fraud. Bank Robbery. Ponzi Scheme. Trees Goodrich, Tamassia

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

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

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.

Information Science 2

COMP 250 Fall binary trees Oct. 27, 2017

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

Lecture 26. Introduction to Trees. Trees

Stacks, Queues and Hierarchical Collections

Some Applications of Stack. Spring Semester 2007 Programming and Data Structure 1

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

CSCI2100B Data Structures Trees

Tree Applications. Processing sentences (computer programs or natural languages) Searchable data structures

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

Successor/Predecessor Rules in Binary Trees

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text)

COSC 2011 Section N. Trees: Terminology and Basic Properties

Introduction to Binary Trees

Stacks, Queues and Hierarchical Collections. 2501ICT Logan

Trees. Tree Structure Binary Tree Tree Traversals

Binary trees. Binary trees. Binary trees

Tree Data Structures CSC 221

Binary Search Tree (2A) Young Won Lim 5/17/18

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

6-TREE. Tree: Directed Tree: A directed tree is an acyclic digraph which has one node called the root node

Data Structures. Trees, Binary trees & Binary Search Trees

EE 368. Week 6 (Notes)

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

CMSC th Lecture: Graph Theory: Trees.

INF2220: algorithms and data structures Series 1

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Analysis of Algorithms

Bioinformatics Programming. EE, NCKU Tien-Hao Chang (Darby Chang)

Advanced Tree Data Structures

Why Do We Need Trees?

Binary Tree. Binary tree terminology. Binary tree terminology Definition and Applications of Binary Trees

Prefix/Infix/Postfix Notation

EE 368. Weeks 5 (Notes)

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

Binary Search Trees. See Section 11.1 of the text.

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

Trees. Introduction & Terminology. February 05, 2018 Cinda Heeren / Geoffrey Tien 1

Postfix (and prefix) notation

Binary Trees Fall 2018 Margaret Reid-Miller

tree nonlinear Examples

Chapter Contents. Trees. Tree Concepts. Hierarchical Organization. Hierarchical Organization. Hierarchical Organization.

OUTLINE. General Trees (Ch. 7.1) Binary Trees (Ch. 7.3) Tree Traversals (Ch. 7.2)

Partha Sarathi Mandal

CSE 373 APRIL 17 TH TREE BALANCE AND AVL

Transcription:

Section 5.5 Binary Tree A binary tree is a rooted tree in which each vertex has at most two children and each child is designated as being a left child or a right child. Thus, in a binary tree, each vertex may have 0, 1, or 2 children. 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 of L, and the edges connecting these vertices. Right subtree The right subtree of a vertex V on a binary tree is the graph formed by the right child R of V, the descendents of R, and the edges connecting these vertices. Expression Tree We will represent an arithmetic expression as a binary tree with the operations as internal vertices. In this representation we let the root denote the final operation done in the expression, and we place the left operand as its left child and the right operand as its right child. If necessary, these process is repeated on these operands. The binary tree created by this process is called an expression tree. Visiting a vertex Processing the data at a vertex is usually called a visiting a vertex (labeled). Traversal A search procedure that visits each vertex of a graph exactly once is called a traversal of the graph. Preorder traversal We will consider a traversal of a binary tree characterized by visiting a parent before its children and a left children before a right child. Listing the vertices in the order they are visited is called a preorder listing. Polish Notation or prefix form The operation sign precedes the operands. When a preorder traversal is performed on an expression tree, the resulting listing of operations and operands is called the prefix form or Polish notation for the expression. Polish Notation Evaluation An expression in Polish notation is evaluated according to the following rule: Scan from left to right until coming to an operation sign, say T, that is followed by two successive numbers, say a and b. Evaluate T a b as a T b, and replace T a b by this value in the expression. Repeat this process until the entire expression is evaluated. Reverse Polish Notation or postfix form The operation sign follows the operands. By using a traversal called postorder, we can obtain the reverse Polish notation for an expression. Reverse Polish Notation Evaluation An expression in Reverse Polish notation is evaluated according to the following rule: Scan from left to right until coming to an operation sign, we look for two numbers say a and b immediately followed by an operation sign T. Evaluate a b T as a T b, and replace a b T by this value in the expression. Repeat this process until the entire expression is evaluated.

Postorder Traversal The postorder traversal is characterized by visiting children before the parent and a left child before a right child. Inorder Traversal The inorder traversal is characterized by visiting a left child before the parent and a right child after the parent. Problem 1. Construct an expression tree for each expression. a) (4 + 2) (6 8) b) (((6 3) 2) + 7)/((5 1) 4 + 8) Problem 2. In the following binary trees, a) Find the right subtree of vertex E, and the left subtree of vertex D. b) Give the preorder listing of vertices.

c) Give the postorder listing of vertices. d) Give the inorder listing of vertices. Problem 3. Find the polish notation for the expressions in a) Problem 1 (a) b) Problem 1 (b)

Problem 4. Find the reverse Polish notation for the expression in a) Problem 1 (a) b) Problem 1 (b) Problem 5. Evaluate the Polish notation expressions. a) + + 4 3 6 2 8 b) + + 3 4 1 2 3 / 4 2

Problem 6. Evaluate the reverse Polish notation expressions. a) 5 6 4 2 2 / + b) 3 4 + 1 2 4 2 / 3 + Problem 7. Construct an expression tree for the Polish notation expression + B D F + A C E.. Problem 8. Construct an expression tree for the Reverse Polish notation expression ED A+BC F +. Homework: Read Section 5.5, do 1-53 (odd).