1 / 21

Graph Theory (Trees)

Graph Theory (Trees) . هواللطیف. ساختمانهای گسسته دانشگاه صنعتی شاهرود – اردیبهشت 1392. 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 . v. v. w. w. x.

roman
Download Presentation

Graph Theory (Trees)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Graph Theory(Trees) هواللطیف ساختمانهای گسسته دانشگاه صنعتی شاهرود – اردیبهشت 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. v v w w x x y z y z v w x y z v w x y z Example (Spanning Trees) Spanning Trees A graph G

  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. v2 v3 v1 2 5 Minimum spanning tree 4 3 7 v5 8 v4 Formal definition of minimum spanning tree • Given a connected undirected graph G. • Let T be a spanning tree of G. • cost(T) = eTweight(e) • The minimum spanning tree is a spanning tree T which minimizes cost(T)

  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. v2 v2 v2 v2 v2 v1 v1 v1 v1 v1 2 2 2 2 2 v3 v3 v3 v3 v3 5 5 5 5 5 4 4 4 4 4 3 3 3 3 3 7 7 7 7 7 8 8 8 8 8 v4 v4 v4 v4 v4 v5 v5 v5 v5 v5 Start from v5, find the minimum edge attach to v5 Find the minimum edge attach to v3 and v5 Find the minimum edge attach to v2, v3 and v5 Find the minimum edge attach to v2, v3 , v4 and v5 Prim’s algorithm (I)

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

  9. Rooted Tree Discrete Mathematical Structures: Theory and Applications

  10. 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

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

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

  13. 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

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

  15. Example + / + 2 2 2 / – 3 2 + 1 0 + / + 2 2 2 / – 3 2 1 + / + 2 2 2 / 1 1 + / + 2 2 2 1 + / 4 2 1 + 2 1 3 CSE 2813 Discrete Structures

  16. Evaluating Postfix Notation • 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 CSE 2813 Discrete Structures

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

  18. Example 2 2 + 2 / 3 2 – 1 0 + / + 4 2 / 3 2 – 1 0 + / + 2 3 2 – 1 0 + / + 2 1 1 0 + / + 2 1 1 / + 2 1 + 3 CSE 2813 Discrete Structures

  19. 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, degreeof v:no. of incident edges to v

More Related