March 20/2003 Jayakanth Srinivasan,

Similar documents
Introduction to Computers and Programming. Concept Question

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

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

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

Binary Trees, Binary Search Trees

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

TREES. Trees - Introduction

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

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

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

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

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

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

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

CSI33 Data Structures

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

CE 221 Data Structures and Algorithms

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

CSI33 Data Structures

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

Binary Trees

Chapter 20: Binary Trees


Trees. Trees. CSE 2011 Winter 2007

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

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

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

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

Elements of Graph Theory

Advanced Tree Data Structures

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

Foundations of Discrete Mathematics

Data Structures and Algorithms for Engineers

COSC 2011 Section N. Trees: Terminology and Basic Properties

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

Trees Algorhyme by Radia Perlman

Associate Professor Dr. Raed Ibraheem Hamed

Trees. Truong Tuan Anh CSE-HCMUT

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

Hamilton paths & circuits. Gray codes. Hamilton Circuits. Planar Graphs. Hamilton circuits. 10 Nov 2015

CS 441 Discrete Mathematics for CS Lecture 26. Graphs. CS 441 Discrete mathematics for CS. Final exam

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

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

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

Graph Theory CS/Math231 Discrete Mathematics Spring2015

Analysis of Algorithms

Trees 11/15/16. Chapter 11. Terminology. Terminology. Terminology. Terminology. Terminology

CS204 Discrete Mathematics. 11 Trees. 11 Trees

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

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

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

Trees, Binary Trees, and Binary Search Trees

Binary Trees Fall 2018 Margaret Reid-Miller

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.

Programming II (CS300)

An undirected graph is a tree if and only of there is a unique simple path between any 2 of its vertices.

Trees. Tree Structure Binary Tree Tree Traversals

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

CPCS Discrete Structures 1

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

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

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

BACKGROUND: A BRIEF INTRODUCTION TO GRAPH THEORY

Successor/Predecessor Rules in Binary Trees

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

Graphs. Introduction To Graphs: Exercises. Definitions:

Graph Algorithms Using Depth First Search

Lecture 26. Introduction to Trees. Trees

EE 368. Weeks 5 (Notes)

Topic Binary Trees (Non-Linear Data Structures)

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

Tree Data Structures CSC 221

Definition of Graphs and Trees. Representation of Trees.

CSC148 Week 6. Larry Zhang

Binary Trees. Height 1

Data Structure. IBPS SO (IT- Officer) Exam 2017

Algorithms and Data Structures

CSC Intro to Intelligent Robotics, Spring Graphs

Search Trees. Undirected graph Directed graph Tree Binary search tree

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Introduction to Binary Trees

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

Binary Trees and Binary Search Trees

THE EULER TOUR TECHNIQUE: EVALUATION OF TREE FUNCTIONS

Data Structures Question Bank Multiple Choice

Terminology. The ADT Binary Tree. The ADT Binary Search Tree

Crossing bridges. Crossing bridges Great Ideas in Theoretical Computer Science. Lecture 12: Graphs I: The Basics. Königsberg (Prussia)

Binary search trees (BST) Binary search trees (BST)

12 Abstract Data Types

Graphs. Pseudograph: multiple edges and loops allowed

Trees. CSE 373 Data Structures

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

(2,4) Trees Goodrich, Tamassia (2,4) Trees 1

CMSC th Lecture: Graph Theory: Trees.

Data Structure - Binary Tree 1 -

Chapter 3 Trees. Theorem A graph T is a tree if, and only if, every two distinct vertices of T are joined by a unique path.

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

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

THE EULER TOUR TECHNIQUE: EVALUATION OF TREE FUNCTIONS

Transcription:

Definition : A simple graph G = (V, E) consists of V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements of V called edges. Definition : In a multigraph G = (V, E) two or more edges may connect the same pair of vertices.

Definition : In a pseudograph G = (V, E) two or more edges may connect the same pair of vertices, and in addition, an edge may connect a vertex to itself. pseudographs multigraphs simple graphs

Definition : In a directed graph G = (V, E) the edges are ordered pairs of (not necessarily distinct) vertices. Definition : In a directed multigraph G = (V, E) the edges are ordered pairs of (not necessarily distinct) vertices, and in addition there may be multiple edges.

TYPE EDGES MULTIPLE EDGES LOOPS ALLOWED? ALLOWED? Simple graph Undirected NO NO Multigraph Undirected YES NO Pseudograph Undirected YES YES Directed graph Directed NO YES Directed multigraph Directed YES YES

Definition : Two vertices, u and v in an undirected graph G are called adjacent (or neighbors) in G, if {u, v} is an edge of G. Definition : The degree of a vertex in an undirected graph is the number of edges incident with it, except that a loop at a vertex contributes twice to the degree of that vertex.

Theorem : Let G = (V, E) be an undirected graph G with e edges. Then deg( v ) = 2 e v ε V The sum of the degrees over all the vertices equals twice the number of edges Definition : A subgraph of a graph G = (V, E) is a graph H = (W, F) where W V and F E.

Definition : A tree is a connected undirected graph with no simple circuits. Theorem : An undirected graph is a tree if and only if there is a unique simple path between any two of its vertices.

a) b) c)

A vertex that has children is called an internal vertex. The subtree at vertex v is the subgraph of the tree consisting of vertex v and its descendants and all edges incident to those descendants.

Definition: A rooted tree is called a binary tree if every internal vertex has no more than 2 children. The tree is called a full binary tree if every internal vertex has exactly 2 children.

Definition: An ordered rooted tree is a rooted tree where the children of each internal vertex are ordered. In an ordered binary tree, the two possible children of a vertex are called the left child and the right child, if they exist.

Theorem: A tree with N vertices has N-1 edges. Theorem: There are at most 2 H leaves in a binary tree of height H. Corallary: If a binary tree with L leaves is full and balanced, then its height is H = log 2 L.

The parent of a non-root vertex is the unique vertex u with a directed edge from u to v. A vertex is called a leaf if it has no children. The ancestors of a non-root vertex are all the vertices in the path from root to this vertex. The descendants of vertex v are all the vertices that have v as an ancestor.

The level of vertex v in a rooted tree is the length of the unique path from the root to v. The height of a rooted tree is the maximum of the levels of its vertices. A rooted binary tree of height H is called balanced if all its leaves are at levels H or H-1.

Each vertex contains a distinct key value, The key values in the tree can be compared using greater than and less than, and The key value of each vertex in the tree is less than every key value in its right subtree, and greater than every key value in its left subtree.

!" # A traversal algorithm is a procedure for systematically visiting every vertex of an ordered binary tree. Tree traversals are defined recursively. Three traversals are named: preorder inorder postorder

$%$&%$!" # Let T be an ordered binary tree with root r. If T has only r then r is the preorder traversal. Else let T 1, T 2 be the left and right subtrees at r. Visit R. Traverse T 1 in preorder Traverse T 2 in preorder.

'$&%$!" # Let T be an ordered binary tree with root r. If T has only r then r is the inorder traversal. Else let T 1, T 2 be the left and right subtrees at r. Traverse T 1 in inorder Visit R. Traverse T 2 in inorder.

$&%$!" # Let T be an ordered binary tree with root r. If T has only r then r is the postorder traversal. Else let T 1, T 2 be the left and right subtrees at r. Traverse T 1 in postorder Traverse T 2 in postorder Visit R.

% ROOT - 8 5 INORDER TRAVERSAL: 8-5 has value 3 PREORDER TRAVERSAL: - 8 5 POSTORDER TRAVERSAL: 8 5 -

% A special kind of binary tree in which: Each leaf node contains a single operand Each nonleaf node contains a single binary operator The left and right subtrees of an operator node represent subexpressions that must be evaluated before applying the operator at the root of the subtree.

% * + 3 4 2 What value does it have? ( 4 + 2 ) * 3 = 18

"% * + 3 4 2 Infix: ( ( 4 + 2 ) * 3 ) Prefix: * + 4 2 3 evaluate from right Postfix: 4 2 + 3 * evaluate from left

(! When a binary expression tree is used to represent an expression, the levels of the nodes in the tree indicate their relative precedence of evaluation. Operations at higher levels of the tree are evaluated later than those below them. The operation at the root is always the last operation performed.

% * - / 8 5 + 3 4 2 Infix: ( ( 8-5 ) * ( ( 4 + 2 ) / 3 ) ) Prefix: * - 8 5 / + 4 2 3 evaluate from right Postfix: 8 5-4 2 + 3 / * evaluate from left