1 / 17

5.5.2 M inimum spanning trees

Learn about Prim and Kruskal's algorithms for finding minimum spanning trees in connected weighted graphs. Understand the theorem behind each algorithm and how they produce optimal spanning trees.

nmcallister
Download Presentation

5.5.2 M inimum spanning 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. 5.5.2 Minimum spanning trees • Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible sum of weights of its edges. • Prim algorithms • Kruskal’s algorithms

  2. 1.Prim’s algorithms • Let T={e} where e is minimum-weighted edge in G • for i=1 to n-2 • begin ei= an edge of minimum weight incident to a vertex in T and not forming a simple circuit in T if added to T • T:=T∪{ei} • end

  3. Theorem 5.17: Prim’s algorithm produces a minimum spanning tree of a connected weighted graph.

  4. 2.Kruskal’s algorithm • T=. • For i=1 to n-1 • begin • ei= an edge of minimum weight in E(G)-E(T) and not forming a simple circuit in T if added to T • T:=T∪{ei} • end

  5. Theorem 5.18: Kruskal’s algorithm produces a minimum spanning tree of a connected weighted graph. • Proof: Let G be a connected weighted graph, and T be the graph which is produced by Kruskal’s algorithm. • By theorem 5.14 • T is a spanning tree of G.

  6. Now we prove T is a minimum spanning tree • Suppose T that is not a minimum spanning tree. Thus there is a spanning tree S of G such that w(S)<w(T). • w(e1 )≤w(e2 )≤≤w(ek )≤≤w(en-1 ) • Suppose ek that is the first edgeS, i.e. e1,e2,,ek-1 are common edges of T and S. • There is a simple circuit C that is in E(S∪{ek}. Then there is an edge e' of C that e'S and e'T. • e1,e2,,ek-1, e'S, thus e1,e2,,ek-1 and e'  any circuit. • By Kruskal’s algorithm, w(ek)≤w(e')

  7. We have a spanning tree S’ which is obtained from S∪ek by omitting the edge e'. • Because w(ek)≤w(e'), w(S')≤w(S), and the number of common edges of S’ and T are added 1. • W(T)≤W(S), • Suppose: W(S)<W(T) • contradiction • Rooted tree and binary tree • Prefix codes and optimal tree

  8. 5.5.3 Rooted tree and binary tree • Definition 25: A directed graph is a directed tree if the graph is a tree in the underlying undirected graph. • Definition 26: A rooted tree is a directed tree if there are exactly a vertex that is 0 in-degree, and other vertices that are 1 in-degree. The vertex of 0 in-degree is called root. And the vertices of 0 out-degree are called leaves. The vertices that are not 0 out-degree are called internal vertices. • There is a unique path from the root to each vertex of the rooted tree by the definition 26

  9. Definition 27: Let u be an internal vertex. If there is a directed edge (u,w) from u to w, then w is called child of u, and u is called the parent of w. If the vertices w1 and w2 are child of u, then w1 and w2 are called brothers. If there a directed path from u to z, then z is called descendant of u. and u is called ancestors of w. The level of a vertex v is the length of the unique path from the root to this vertex. The level of the root is defined to be zero. The height of a rooted tree is the maximum of the levels of all vertices. • Note: The parent of w is unique.

  10. Root:1 • Leaf: 6, 8, 9, 10, 11, 12 • internal vertices: 1, 2, 3, 4, 5, 7 • the levels of 2, 3 are 1, the levels of 4, 5, 6, 7, 8 are 2 , • the levels of 9, 10, 11, 12 are 3 。 • The height of a rooted tree is 3

  11. Definition 28: If v be a vertex of a rooted tree, then the subtree with v as its root is the subgraph of the tree consisting of v and its descendants and all edges incident to these descendants.

  12. Definition 29: An ordered rooted tree is a rooted tree where the children of each internal vertex are ordered. Ordered rooted trees are drawn so that the children of each internal vertex and edges are shown in order from left to right, and these edges are marked on 1,2,,i,

  13. Definition 30: An ordered rooted tree is called an m-ary tree if every vertex has no more than m children. The tree is called a full m-ary tree if every vertex has exactly m children. An m-ary tree with m=2 is called a binary tree. • Left subtree, right subtree

  14. a-(b+(c/d)+(e/f))

  15. Theorem 5.19: A full binary tree with t leaves contains i=t-1 internal vertices. • Proof: Let the number vertices be n. • The sum of children of all internal vertices equals n-1, • internal vertices and leaves • the number vertices n=i+t, • i.e. 2i=i+t-1, • Thus i=t-1。 • A full m-ary tree with t leaves contains i=(t-1)/(m-1) internal vertices.

  16. Next: Binary tree • Prefix codes and optimal tree • Exercise P285 2,5,11,14,18,20,21,24 • P259 23

More Related