Trees. Arash Rafiey. 20 October, 2015

Similar documents
Searching in Graphs (cut points)

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

(Re)Introduction to Graphs and Some Algorithms

22.1 Representations of graphs

CS 220: Discrete Structures and their Applications. graphs zybooks chapter 10

Algorithm Design and Analysis

Copyright 2000, Kevin Wayne 1

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11

Lecture 3: Graphs and flows

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,

These notes present some properties of chordal graphs, a set of undirected graphs that are important for undirected graphical models.

CS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs


CSE 2331/5331. Topic 9: Basic Graph Alg. Representations Basic traversal algorithms Topological sort CSE 2331/5331

Trees. 3. (Minimally Connected) G is connected and deleting any of its edges gives rise to a disconnected graph.

We will show that the height of a RB tree on n vertices is approximately 2*log n. In class I presented a simple structural proof of this claim:

CS 310 Advanced Data Structures and Algorithms

Trees Algorhyme by Radia Perlman

implementing the breadth-first search algorithm implementing the depth-first search algorithm

Algorithms and Theory of Computation. Lecture 3: Graph Algorithms

Graphs. Part I: Basic algorithms. Laura Toma Algorithms (csci2200), Bowdoin College

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

Info 2950, Lecture 16

Graph Representation

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.

22.3 Depth First Search

Graphs and trees come up everywhere. We can view the internet as a graph (in many ways) Web search views web pages as a graph

CS200: Graphs. Rosen Ch , 9.6, Walls and Mirrors Ch. 14

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

CSC Design and Analysis of Algorithms. Lecture 4 Brute Force, Exhaustive Search, Graph Traversal Algorithms. Brute-Force Approach

CS/COE

Chapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1

Graph Algorithms. Imran Rashid. Jan 16, University of Washington

Depth-First Search Depth-first search (DFS) is another way to traverse the graph.

Graph Definitions. In a directed graph the edges have directions (ordered pairs). A weighted graph includes a weight function.

Introduction to Graphs

v V Question: How many edges are there in a graph with 10 vertices each of degree 6?

CSE 417: Algorithms and Computational Complexity

Graph traversal is a generalization of tree traversal except we have to keep track of the visited vertices.

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

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

Algorithm Design and Analysis

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

Lecture 7. s.t. e = (u,v) E x u + x v 1 (2) v V x v 0 (3)

Solutions to relevant spring 2000 exam problems

3.1 Basic Definitions and Applications

4 Basics of Trees. Petr Hliněný, FI MU Brno 1 FI: MA010: Trees and Forests

Graph Algorithms. Definition

Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M.

Graph: representation and traversal

CS4800: Algorithms & Data Jonathan Ullman

CSE 331: Introduction to Algorithm Analysis and Design Graphs

Applications of BDF and DFS

Figure 1: A directed graph.

Practical Session No. 12 Graphs, BFS, DFS, Topological sort

Graph Algorithms. Andreas Klappenecker. [based on slides by Prof. Welch]

Outline. Graphs. Divide and Conquer.

Graphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V)

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number:

11.2 Eulerian Trails

Foundations of Discrete Mathematics

Fundamental Algorithms

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

Theory of Computing. Lecture 4/5 MAS 714 Hartmut Klauck

W4231: Analysis of Algorithms

Algorithms: Lecture 10. Chalmers University of Technology

Parallel Breadth First Search

Graph Algorithms Using Depth First Search

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1

Introduction to Optimization

Module 11: Additional Topics Graph Theory and Applications

Graph Traversals. CS200 - Graphs 1

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

Algorithmic Aspects of Communication Networks

Brute Force: Selection Sort

DFS & STRONGLY CONNECTED COMPONENTS

1 Digraphs. Definition 1

Graph Representations and Traversal

Elements of Graph Theory

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

CS 206 Introduction to Computer Science II

Graph Algorithms. Andreas Klappenecker

CSE 417: Algorithms and Computational Complexity. 3.1 Basic Definitions and Applications. Goals. Chapter 3. Winter 2012 Graphs and Graph Algorithms

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

Foundations of Computer Science Spring Mathematical Preliminaries

Some major graph problems

Lecture 10: Strongly Connected Components, Biconnected Graphs

Figure 4.1: The evolution of a rooted tree.

Graph Algorithms. Chromatic Polynomials. Graph Algorithms

This course is intended for 3rd and/or 4th year undergraduate majors in Computer Science.

MA/CSSE 473 Day 12. Questions? Insertion sort analysis Depth first Search Breadth first Search. (Introduce permutation and subset generation)

LECTURE 17 GRAPH TRAVERSALS

Discrete mathematics

Basic Graph Definitions

3.1 Basic Definitions and Applications. Chapter 3. Graphs. Undirected Graphs. Some Graph Applications

Graph Theory CS/Math231 Discrete Mathematics Spring2015

Definition: A graph G = (V, E) is called a tree if G is connected and acyclic. The following theorem captures many important facts about trees.

K 4 C 5. Figure 4.5: Some well known family of graphs

Chapter 11: Graphs and Trees. March 23, 2008

Transcription:

20 October, 2015

Definition Let G = (V, E) be a loop-free undirected graph. G is called a tree if G is connected and contains no cycle.

Definition Let G = (V, E) be a loop-free undirected graph. G is called a tree if G is connected and contains no cycle. Theorem If a, b are distinct vertices in tree T = (V, E), then there is a unique path from a to b in T.

Definition Let G = (V, E) be a loop-free undirected graph. G is called a tree if G is connected and contains no cycle. Theorem If a, b are distinct vertices in tree T = (V, E), then there is a unique path from a to b in T. Proof. Since T is connected, there is a path from a to b. If there is another path from a to b then we get a cycle by union the two paths.

Theorem In every tree T = (V, E), V = E + 1.

Theorem In every tree T = (V, E), V = E + 1. Proof. We use induction on the number of edges. If E = 0 then it is clear that T has only one vertex. Let e = uv be an edge in T. By removing e we would have two subtrees T 1 = (V 1, E 1 ) and T 2 = (V 2, E 2 ). Observe that E 1 < E and E 2 < E. By induction hypothesis T 1 = E 1 + 1 and T 2 = E 2 + 1. We have T = T 1 + T 2 and E = E 1 + E 2 + 1. Therefore T = E + 1.

Theorem Every tree T = (V, E) with at least two vertices has at least two leaves (vertex of degree 1).

Theorem Every tree T = (V, E) with at least two vertices has at least two leaves (vertex of degree 1). Proof. Set n = T. We know that E = n 1. If there are k leaves then 2(n 1) = 2 E = v V deg(v) k + 2(n k). Therefore k 2.

Labeling A labeled tree with n vertices is a tree where each vertex has a label from {1, 2,..., n} (distinct labels). The number of non-isomorphic trees with n labels is n n 2.

Labeling A labeled tree with n vertices is a tree where each vertex has a label from {1, 2,..., n} (distinct labels). The number of non-isomorphic trees with n labels is n n 2. This can be viewed as the number of sequences x 1, x 2,..., x n 2 where each x i {1, 2,..., n}.

Labeling A labeled tree with n vertices is a tree where each vertex has a label from {1, 2,..., n} (distinct labels). The number of non-isomorphic trees with n labels is n n 2. This can be viewed as the number of sequences x 1, x 2,..., x n 2 where each x i {1, 2,..., n}. From each labeling we obtain a sequence as follows. 1) Start with i = 1. 2) Set x i to be the parent of the smallest labeled leaf y j. 3) Remove the leaf and increase i by one. If i = n 2 stops otherwise go to (2).

Definition If G is a directed graph, then G is called a directed tree if the undirected graph associated with G is a tree. When G is a directed tree, G is called rooted tree if there is a unique vertex r, called root, in G with indegree zero, and for all other vertices v, the in degree of v is 1.

Definition If G is a directed graph, then G is called a directed tree if the undirected graph associated with G is a tree. When G is a directed tree, G is called rooted tree if there is a unique vertex r, called root, in G with indegree zero, and for all other vertices v, the in degree of v is 1. a b a c d b c e d e f f g h i g h

Definition If G is a directed graph, then G is called a directed tree if the undirected graph associated with G is a tree. When G is a directed tree, G is called rooted tree if there is a unique vertex r, called root, in G with indegree zero, and for all other vertices v, the in degree of v is 1. a b a c d b c e d e f f g h i g h For simplicity we may ignore the direction once the root identified.

Traversing a tree starting from root Breadth-First Search Method : Visiting the vertices of the tree level by level starting from root r Breadth-First Search (BFS). Start with node r and set L 0 = r. At step i let L i be the set of nodes that are not in any of L 0, L 1,..., L i 1 and have a neighbor in L i 1. Lemma L j is the set of nodes that are at distance exactly j from r.

Traversing a tree starting from root Breadth-First Search Method : Visiting the vertices of the tree level by level starting from root r Breadth-First Search (BFS). Start with node r and set L 0 = r. At step i let L i be the set of nodes that are not in any of L 0, L 1,..., L i 1 and have a neighbor in L i 1. Lemma L j is the set of nodes that are at distance exactly j from r. 1 7 1 1 1 2 2 3 2 3 2 3 3 5 4 8 4 5 7 8 4 5 7 8 6 6

Depth-First Search (backtracking approach) We don t visit the nodes level by level! As long as there is an unvisited node adjacent to the current visited node we continue! Once we are stuck, trace back and go to a different branch!

Depth-First Search (backtracking approach) We don t visit the nodes level by level! As long as there is an unvisited node adjacent to the current visited node we continue! Once we are stuck, trace back and go to a different branch! PreorderDFS (r) 1. Mark r as Explored and print r. 2. For every edge rv 3. If v is not Explored then call PreorderDFS (v)

Depth-First Search (backtracking approach) We don t visit the nodes level by level! As long as there is an unvisited node adjacent to the current visited node we continue! Once we are stuck, trace back and go to a different branch! PreorderDFS (r) 1. Mark r as Explored and print r. 2. For every edge rv 3. If v is not Explored then call PreorderDFS (v) a b c d e f Pre DFS : a, b, d, e, c, f, g, h g h

DFSpostorder (r) 1. Mark r as Explored 2. For every edge rv 3. If v is not Explored then call DFSpostorder (v) 4. Print r.

DFSpostorder (r) 1. Mark r as Explored 2. For every edge rv 3. If v is not Explored then call DFSpostorder (v) 4. Print r. a b c d e f Post DFS : d, e, b, g, h, f, c, a g h