ساختمانهای گسسته دانشگاه صنعتی شاهرود – اردیبهشت 1392.

Slides:



Advertisements
Similar presentations
Chapter 10, Section 10.3 Tree Traversal
Advertisements

Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
1 Tree Traversal Section 9.3 Longin Jan Latecki Temple University Based on slides by Paul Tymann, Andrew Watkins, and J. van Helden.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Edited by Malak Abdullah Jordan University of Science and Technology Data Structures Using C++ 2E Chapter 12 Graphs.
Discrete Structures Lecture 13: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
CMPS 2433 Discrete Structures Chapter 5 - Trees R. HALVERSON – MIDWESTERN STATE UNIVERSITY.
Advanced Topics in Algorithms and Data Structures 1 Rooting a tree For doing any tree computation, we need to know the parent p ( v ) for each node v.
Discrete Mathematics Transparency No. 8-1 Chapter 8 Trees.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A12 – Binary Trees.
Tree Traversal. Traversal Algorithms preorder inorder postorder.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
4/17/2017 Section 9.3 Tree Traversal ch9.3.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A12 – Binary Trees.
CS 206 Introduction to Computer Science II 03 / 25 / 2009 Instructor: Michael Eckmann.
Transforming Infix to Postfix
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Trees.
Tree Traversal. Traversal Algorithms preorder inorder postorder.
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE The trees.
Trees and Tree Traversals Prof. Sin-Min Lee Department of Computer Science San Jose State University.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
Chapter Chapter Summary Introduction to Trees Applications of Trees (not currently included in overheads) Tree Traversal Spanning Trees Minimum.
10.3 Tree Transversal. Pre/post fix notation and order See handout. a.bc.d e f g h i j k.
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
Chapter 2 Graph Algorithms.
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
LOGO.  Trees:  In these slides: Introduction to trees Applications of trees Tree traversal 2.
COSC 2007 Data Structures II Chapter 14 Graphs III.
Section 10.1 Introduction to Trees These class notes are based on material from our textbook, Discrete Mathematics and Its Applications, 6 th ed., by Kenneth.
Binary Trees 2 Overview Trees. Terminology. Traversal of Binary Trees. Expression Trees. Binary Search Trees.
CSCI 115 Chapter 7 Trees. CSCI 115 §7.1 Trees §7.1 – Trees TREE –Let T be a relation on a set A. T is a tree if there exists a vertex v 0 in A s.t. there.
Lecture 8 Tree.
Tree Data Structures.
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
Discrete Structures Trees (Ch. 11)
Chap 8 Trees Def 1: A tree is a connected,undirected, graph with no simple circuits. Ex1. Theorem1: An undirected graph is a tree if and only if there.
Chapter 7. Trees Weiqi Luo ( 骆伟祺 ) School of Software Sun Yat-Sen University : Office : A309
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
Chapter 12 Abstract Data Type. Understand the concept of an abstract data type (ADT). Understand the concept of a linear list as well as its operations.
Trees By P.Naga Srinivasu M.tech,(MBA). Basic Tree Concepts A tree consists of finite set of elements, called nodes, and a finite set of directed lines.
CS 103 Discrete Structures Lecture 23 Trees (1). Second Midterm Exam 1 st Lecture in December (same time as the lecture) 75 minute duration Will cover.
Lecture 17: Trees and Networks I Discrete Mathematical Structures: Theory and Applications.
Chapter 10: Trees A tree is a connected simple undirected graph with no simple circuits. Properties: There is a unique simple path between any 2 of its.
1 Trees 2 Binary trees Section Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children –Left and.
Data Structures Azhar Maqsood School of Electrical Engineering and Computer Sciences (SEECS-NUST) Binary Trees.
Graphs and Trees Mathematical Structures for Computer Science Chapter 5 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesGraphs and Trees.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Discrete Mathematics Chapter 10 Trees. Outline 10.1 Introduction to Trees 10.2 Applications of Trees 10.3 Tree Traversal 10.4 Spanning Trees 10.5 Minimal.
Discrete Mathematics Chapter 10 Trees.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Chapter 11. Chapter Summary Introduction to Trees Applications of Trees (not currently included in overheads) Tree Traversal Spanning Trees Minimum Spanning.
Discrete Mathematics Trees.
Chapter 12 Abstract Data Type.
Applied Discrete Mathematics Week 15: Trees
Trees Chapter 15.
Chapter 5 : Trees.
Minimum Spanning Tree Chapter 13.6.
Trees Chapter 11.
Paul Tymann and Andrew Watkins
12. Graphs and Trees 2 Summary
Data Structures Review Session 2
CS120 Graphs.
Connected Components Minimum Spanning Tree
Paul Tymann, Andrew Watkins,
Section 9.3 by Andrew Watkins
Paul Tymann, Andrew Watkins,
And the Final Subject is…
Trees Chapter 11.
Presentation transcript:

ساختمانهای گسسته دانشگاه صنعتی شاهرود – اردیبهشت 1392

2 Spanning Trees Let G be a connected graph. A spanning tree in G is a subgraph of G that includes all the vertices of G and is also a tree. The edges of the tree are called branches.

3 Example (Spanning Trees) v w x y z vw x y z vw x y z v w x y z A graph G Spanning Trees

4 Minimum Spanning Tree Consider a connected undirected graph where –Each node x represents a country x –Each edge (x, y) has a number which measures the cost of placing telephone line between country x and country y Problem: connecting all countries while minimizing the total cost Solution: find a spanning tree with minimum total weight, that is, minimum spanning tree

5 Formal definition of minimum spanning tree Given a connected undirected graph G. Let T be a spanning tree of G. cost(T) =  e  T weight(e) The minimum spanning tree is a spanning tree T which minimizes cost(T) v1v1 v4v4 v3v3 v5v5 v2v Minimum spanning tree

6 Prim’s algorithm (II) Algorithm PrimAlgorithm(v) Mark node v as visited and include it in the minimum spanning tree; while (there are unvisited nodes) { –find the minimum edge (v, u) between a visited node v and an unvisited node u; –mark u as visited; –add both v and (v, u) to the minimum spanning tree; }

7 Prim’s algorithm (I) Start from v 5, find the minimum edge attach to v 5 v2v2 v1v1 v4v4 v3v3 v5v Find the minimum edge attach to v 3 and v 5 v2v2 v1v1 v4v4 v3v3 v5v Find the minimum edge attach to v 2, v 3 and v 5 v2v2 v1v1 v4v4 v3v3 v5v v2v2 v1v1 v4v4 v3v3 v5v v2v2 v1v1 v4v4 v3v3 v5v Find the minimum edge attach to v 2, v 3, v 4 and v 5

8 Minimum Spanning Trees Minimum Spanning Trees Given a weighted undirected graph, compute the spanning tree with the minimum cost Given a weighted undirected graph, compute the spanning tree with the minimum cost

9

Discrete Mathematical Structures: Theory and Applications 10 Rooted Tree

CSE 2813 Discrete Structures Representing Arithmetic Expressions Complicated arithmetic expressions can be represented by an ordered rooted tree –Internal vertices represent operators –Leaves represent operands Build the tree bottom-up –Construct smaller subtrees –Incorporate the smaller subtrees as part of larger subtrees

CSE 2813 Discrete Structures Example ( x + y ) 2 + ( x -3)/( y +2) + x y 2  – x 3 + y 2 / +

CSE 2813 Discrete Structures Infix Notation +  – + / + 2 x y x 3 y 2 Traverse in inorder adding parentheses for each operation x + y ()  2 () + x – 3() / y + 2() () ()

CSE 2813 Discrete Structures Evaluating Prefix Notation In an prefix expression, a binary operator precedes its two operands The expression is evaluated right-left Look for the first operator from the right Evaluate the operator with the two operands immediately to its right

CSE 2813 Discrete Structures Prefix Notation (Polish Notation) Traverse in preorder x + y  2 + x – 3 / y  – + / + 2 x y x 3 y 2

CSE 2813 Discrete Structures Example + / / – / / – / / / /

CSE 2813 Discrete Structures In an postfix expression, a binary operator follows its two operands The expression is evaluated left-right Look for the first operator from the left Evaluate the operator with the two operands immediately to its left Evaluating Postfix Notation

CSE 2813 Discrete Structures Postfix Notation (Reverse Polish) Traverse in postorder x + y  2 + x – 3 / y  – + / + 2 x y x 3 y 2

CSE 2813 Discrete Structures Example / 3 2 – / / 3 2 – / – / / /

Definitions Vertex w is adjacent to vertex v if there is an edge ( v,w ). Given an edge e = (u,v) in an undirected graph, u and v are the endpoints of e and e is incident on u (or on v ). In a digraph, u & v are the origin and destination. e leaves u and enters v. A digraph or graph is weighted if its edges are labeled with numeric values. In a digraph, –Out-degree of v : number of edges coming out of v –In-degree of v : number of edges coming in to v In a graph, degree of v: no. of incident edges to v

21