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

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

March 20/2003 Jayakanth Srinivasan,

Introduction to Computers and Programming. Concept Question

Binary Trees, Binary Search Trees

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

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

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

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

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

TREES. Trees - Introduction

CE 221 Data Structures and Algorithms

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

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

Binary Trees

Trees. Truong Tuan Anh CSE-HCMUT


CSI33 Data Structures

Associate Professor Dr. Raed Ibraheem Hamed

Discrete Mathematics. Chapter 7. trees Sanguk Noh

Trees. Trees. CSE 2011 Winter 2007

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

CSI33 Data Structures

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

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

Trees Algorhyme by Radia Perlman

Programming II (CS300)

Trees. Tree Structure Binary Tree Tree Traversals

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

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

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

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

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

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.

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

Analysis of Algorithms

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

Todays Lecture. Assignment 2 deadline: You have 5 Calendar days to complete.

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

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

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

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

Successor/Predecessor Rules in Binary Trees

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

Stacks, Queues and Hierarchical Collections. 2501ICT Logan

Trees, Binary Trees, and Binary Search Trees

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010

CISC 235 Topic 3. General Trees, Binary Trees, Binary Search Trees

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

Data Structures and Algorithms for Engineers

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

Stacks, Queues and Hierarchical Collections

ROOT: A node which doesn't have a parent. In the above tree. The Root is A.

Advanced Tree Data Structures

Topic 18 Binary Trees "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb

12 Abstract Data Types

CS204 Discrete Mathematics. 11 Trees. 11 Trees

E.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.

Why Do We Need Trees?

Chapter 20: Binary Trees

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


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

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Electronics and Communication

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

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

Data Structure - Binary Tree 1 -

Garbage Collection: recycling unused memory

Trees. CSE 373 Data Structures

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

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 11/15/16. Chapter 11. Terminology. Terminology. Terminology. Terminology. Terminology

COMP 250 Fall binary trees Oct. 27, 2017

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees

Course Review for. Cpt S 223 Fall Cpt S 223. School of EECS, WSU

CSC148 Week 6. Larry Zhang

DYNAMIC MEMORY ALLOCATION AND DEALLOCATION

Recursive Data Structures and Grammars

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

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

CMSC th Lecture: Graph Theory: Trees.

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

Introduction to Binary Trees

Carlos Delgado Kloos Mª Carmen Fernández Panadero Raquel M. Crespo García Dep. Ingeniería Telemática Univ. Carlos III de Madrid

Algorithms and Data Structures

(2,4) Trees. 2/22/2006 (2,4) Trees 1

COSC 2011 Section N. Trees: Terminology and Basic Properties

Tree Data Structures CSC 221

Binary Trees. Height 1

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

University of Palestine. Final Exam 2 nd semester 2014/2015 Total Grade: 50

Definitions A A tree is an abstract t data type. Topic 17. "A tree may grow a. its leaves will return to its roots." Properties of Trees

12/5/17. trees. CS 220: Discrete Structures and their Applications. Trees Chapter 11 in zybooks. rooted trees. rooted trees

EE 368. Weeks 5 (Notes)

INF2220: algorithms and data structures Series 1

DATA STRUCTURES USING C

CHAPTER 11 Trees. 294 Chapter 11 Trees. f) This is a tree since it is connected and has no simple circuits.

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

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

Transcription:

Chapter 4 Trees 4-1 Trees and Spanning Trees Trees, T: A simple, cycle-free, loop-free graph satisfies: If v and w are vertices in T, there is a unique simple path from v to w. Eg. Trees. Spanning trees: A subgraph of G is a tree and it contains all of the vertices of G. Eg. Two examples of graphs and their respective corresponding spanning trees. Theorem A graph G has a spanning tree if and only if G is connected.

Breadth-first search for spanning trees algorithm Depth-first search for spanning trees algorithm

Minimal Spanning trees: A spanning tree with minimum weight. Eg. For the following leftmost graph G, T and T are both the spanning trees of G, the weight of T is 12 and that of T is 20, we can see that T is a minimal spanning tree. Prim s algorithm

Eg. Find the minimal spanning tree of the left graph. (Sol.) Eg. Find the minimal spanning tree of the left graph. (Sol.)

Eg. Find the minimal spanning tree of the left graph by Prim s algorithm. Select vertex 5 as the root. (Sol.) Eg. Find the minimal spanning tree of the left graph. (Sol.)

4-2 Binary Trees Binary tree: A binary tree is a rooted tree in which each vertex has either 2 children (a left child and aright child), one child (a left child or a right child, but not both), or no child. Eg. Three examples of binary trees. Full binary tree: A full binary tree in which each vertex has either 2 children or zero children. Theorem If T is a full binary tree with i internal vertices, then T has i +1 terminal vertices and 2i +1 total vertices. Theorem If a binary tree of height h has t terminal vertices, then log 2 (t) h. Eg. A binary tree has height h and the number of terminals t=8. Child-Sibling Rules: To transform a general tree into a binary tree according to the following procedures. 1. Connect all brothers in the same level using the horizontal edges from the left one to the right one. 2. Delete all the links between the vertex (node) and its children except the leftmost child. 3. Turn the horizontal edges 45 clockwise.

Eg. Transform the left tree into a binary tree. (Sol.)

4-3 Tree Traversals Preorder traversal algorithm 1. Starting from the root, firstly visited the left child, and then visited the right child. 2. After visiting all the left descendants of a node, we can visit its right descendants. Eg. For the left binary tree, preorder traversal yields: 7, 6, 2, 1, 4, 3, 5, 8, 10, 9, 12, 11, 13. Eg. For the left binary tree, preorder traversal yields: 5, 2, 1, 4, 10, 8. Postorder traversal algorithm 1. Starting from the leftmost child, firstly visited its right brother, and then visited their parent. 2. After visiting all the descendants, we can visit the ancestor on the higher level.

Eg. For the left binary tree, postorder traversal yields: D, E, B, F, G, C, A. Inorder traversal algorithm Eg. For the binary tree, Preorder traversal is A, B, C, D, E, F, G, H, I, and J. Postorder traversal is C, E, D, B, I, J, H, G, F, and A. Inorder traversal is C, B, D, E, A, F, I, H, J, and G. Eg. For the binary tree, the preorder traversal yields: 2, 7, 2, 6, 5, 11, 5, 9, 4. And the postorder traversal yields: 2, 5, 11, 6, 7, 4, 9, 5, 2. The inorder traversal yields: 2, 7, 5, 6, 11, 2, 5, 4, 9

Application of tree traversals: Facilitating the computer evaluation of arithmetic expression. Rules of transforming arithmetic expression into a binary tree and then obtaining the prefix, the infix, and the postfix forms: 1. Add appropriate parentheses in the arithmetic expression. 2. Starting from the innermost parenthesis, the operator is as the root, the left operand is as the left child and the right operand is as the right child. 3. Obtain the prefix, the infix, and the postfix forms according to the preorder, the inorder, and the postorder traversal algorithms, respectively. Eg. Transform an expression involving the operators (A+B)*C-D/E into the prefix, the infix, and the postfix forms. (Sol.) Rewrite (A+B)*C-D/E into (((A+B)*C)-(D/E)) and obtain the tree as Prefix form: -*+ABC/DE Postfix form: AB+C*DE/- Eg. Transform an expression involving the operators (A+B)/((C*D)-E) into the prefix, the infix, and the postfix forms. (Sol.) Traverse the left binary tree, we have Prefix form: /+AB-*CDE Infix form: A+B/C*D-E Postfix form: AB + CD*E-/