Chapter 11 Trees Graphs III (Trees, MSTs) Reading: Epp Chp 11.5, 11.6.

Slides:



Advertisements
Similar presentations
Chapter 5: Tree Constructions
Advertisements

Chapter 23 Minimum Spanning Tree
Trees Chapter 11.
 Theorem 5.9: Let G be a simple graph with n vertices, where n>2. G has a Hamilton circuit if for any two vertices u and v of G that are not adjacent,
Chapter 9 Graphs.
Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
Greedy Algorithms Greed is good. (Some of the time)
22C:19 Discrete Structures Trees Spring 2014 Sukumar Ghosh.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Graphs III (Trees, MSTs) (Chp 11.5, 11.6)
3.3 Spanning Trees Tucker, Applied Combinatorics, Section 3.3, by Patti Bodkin and Tamsen Hunter.
CMPS 2433 Discrete Structures Chapter 5 - Trees R. HALVERSON – MIDWESTERN STATE UNIVERSITY.
1 Chapter 10 Trees. Tree Definition 1. A tree is a connected undirected graph with no simple circuits. Theorem 1. An undirected graph is a tree if and.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
Discrete Mathematics Transparency No. 8-1 Chapter 8 Trees.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 13 Minumum spanning trees Motivation Properties of minimum spanning trees Kruskal’s.
1 Minimum Spanning Trees Gallagher-Humblet-Spira (GHS) Algorithm.
Section 3.1 Properties of Trees Sarah Graham. Tree Talk: Vocabulary oTree: a tree is a special type of graph that contains designated vertex called a.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Graphs and Trees This handout: Trees Minimum Spanning Tree Problem.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Is the following graph Hamiltonian- connected from vertex v? a). Yes b). No c). I have absolutely no idea v.
Rooted Trees. More definitions parent of d child of c sibling of d ancestor of d descendants of g leaf internal vertex subtree root.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Design and Analysis of Algorithms Minimum Spanning trees
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Trees.
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
Minimum Spanning Trees. Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a.
May 5, 2015Applied Discrete Mathematics Week 13: Boolean Algebra 1 Dijkstra’s Algorithm procedure Dijkstra(G: weighted connected simple graph with vertices.
Minimal Spanning Trees What is a minimal spanning tree (MST) and how to find one.
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
May 1, 2002Applied Discrete Mathematics Week 13: Graphs and Trees 1News CSEMS Scholarships for CS and Math students (US citizens only) $3,125 per year.
Foundations of Discrete Mathematics
7.1 and 7.2: Spanning Trees. A network is a graph that is connected –The network must be a sub-graph of the original graph (its edges must come from the.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Euler paths and tours.
Tree A connected graph that contains no simple circuits is called a tree. Because a tree cannot have a simple circuit, a tree cannot contain multiple.
Binary Trees. Binary Tree Finite (possibly empty) collection of elements A nonempty binary tree has a root element The remaining elements (if any) are.
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.
Discrete Structures Lecture 12: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
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.
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.
Introduction to Graph Theory
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.
Agenda Review: –Planar Graphs Lecture Content:  Concepts of Trees  Spanning Trees  Binary Trees Exercise.
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.
CMSC 341 Introduction to Trees. 2/21/20062 Tree ADT Tree definition –A tree is a set of nodes which may be empty –If not empty, then there is a distinguished.
Trees Dr. Yasir Ali. A graph is called a tree if, and only if, it is circuit-free and connected. A graph is called a forest if, and only if, it is circuit-free.
CHAPTER 11 TREES INTRODUCTION TO TREES ► A tree is a connected undirected graph with no simple circuit. ► An undirected graph is a tree if and only.
Week 11 - Friday.  What did we talk about last time?  Paths and circuits  Matrix representation of graphs.
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 Structures Li Tak Sing( 李德成 ) Lectures
Trees.
Applied Discrete Mathematics Week 15: Trees
Chapter 5 : Trees.
Minimum Spanning Tree Chapter 13.6.
Discrete Mathematicsq
12. Graphs and Trees 2 Summary
Introduction to Trees Section 11.1.
CMSC 341 Introduction to Trees.
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Advanced Algorithms Analysis and Design
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 10 Trees Slides are adopted from “Discrete.
CS 583 Analysis of Algorithms
Minimum Spanning Tree Algorithms
Trees 11.1 Introduction to Trees Dr. Halimah Alshehri.
And the Final Subject is…
Presentation transcript:

Chapter 11 Trees Graphs III (Trees, MSTs) Reading: Epp Chp 11.5, 11.6

Outline 1.Trees 1.1 Definition of a tree. 1.2 Examples of trees. 1.3 Theorem #1: Tree Characterization 2.Rooted Trees 2.1 Definitions 2.2 Definition: n-ary trees and binary trees. 2.3 Definition: Full n-ary trees 2.4 Theorem #2: Full Tree 2.5 Theorem #3: Leaves-Height 2.6 Examples 3.Spanning Trees 3.1 Motivation 3.2 Definition 3.3 Theorem #4: Spanning Tree 3.4 Minimum Spanning Tree (MST) 3.5 Kruskals Algorithm 3.6 Prims Algorithm

1. Trees 1.1 Definition: Let G=(V,E). G is a tree IFF (a) G is connected; and (b) G does not have any circuits (acyclic). Comment: –The textbook distinguishes between trivial and non-trivial circuits. They define a trivial circuit as a circuit of length 0. –As far as we are concerned, unless otherwise stated, when we say circuit we mean NON- TRIVIAL circuit. i.e. the default meaning of circuit is a non-trivial circuit.

1. Trees 1.1 Definition: Let G=(V,E). G is a tree IFF (a) G is connected; and (b) G does not have any circuits (acyclic) Example of a tree

1. Trees Examples of trees in real life usage –Family Tree –Tournaments –Directory Tree –Syntax Tree –Execution Tree –Decision Tree –Search Tree –B-Tree (Databases)

1. Trees 1.3 Theorem (Tree Characterization Theorem): Let G=(V,E). G is a tree IFF G is connected and |E|=|V|-1 n Proof Strategy: –( ) Assume G is a tree Prove that G is connected(Trivial) Prove that |E| = |V| - 1(Prove by induction on |V|) –Lemma 1: A tree with more than 1 vertex has at least 1 vertex of degree 1 –( ) Assume G is connected and |E| = |V| -1 (Prove that G is a tree. How? Show that G fits the definition of a tree.) Prove that G is connected(Trivial) Prove that G has no circuits(Prove by contradiction) –Lemma 2: Deletion of edge from a circuit of a connected graph does not violate connectedness.

Outline 1.Trees 1.1 Definition of a tree. 1.2 Examples of trees. 1.3 Theorem #1: Tree Characterization 2.Rooted Trees 2.1 Definitions 2.2 Definition: n-ary trees and binary trees. 2.3 Definition: Full n-ary trees 2.4 Theorem #2: Full Tree 2.5 Theorem #3: Leaves-Height 2.6 Examples 3.Spanning Trees 3.1 Motivation 3.2 Definition 3.3 Theorem #4: Spanning Tree 3.4 Minimum Spanning Tree (MST) 3.5 Kruskals Algorithm 3.6 Prims Algorithm

2.1 Rooted Trees (Definition) n A rooted tree is a tree in which one vertex is distinguished from the others and is called the root. n The level of a vertex v is the path length from the root to v. The height of the tree is the maximum level to any vertex of the tree. root Level 0 Level 1 Level 2 Level 3 Level 4

2.1 Rooted Trees (Definition) n Given any vertex v in a rooted tree: –The children of v are the vertices adjacent to v, 1 level further away from the root. –The parent of v is the vertex adjacent to v, 1 level nearer to the root. –The siblings of v are the vertices which have the same parent as v. v Parent of v Children of v Siblings of v

2.1 Rooted Trees (Definition) n Given any vertex v in a rooted tree: –The ancestor of v are the vertices which lie in the path from v to the root. –If u is the ancestor of v, then v is the descendant of u. v Ancestors of v Descendants of v

2.1 Rooted Trees (Definition) n Given any rooted tree: –The internal vertices of the tree are the vertices which have at least 1 child. –The external vertices of the tree are the vertices which have no children. External vertices are also known as the leaves of the tree, or terminal vertices. External Vertices (Leaves) The rest are Internal Vertices

2.2 m-ary trees and binary trees (Defn) n A m-ary tree is a rooted tree in which every vertex has at most m children. Example of a 4-ary Tree Example of a 3-ary Tree

2.2 m-ary trees and binary trees (Defn) n A m-ary tree is a rooted tree in which every vertex has at most m children. –A binary tree is a m-ary tree with n=2. Each child of the binary tree is designated either the left child or the right child. Given a vertex v of a binary tree, the left subtree of v (right subtree of v) is the binary tree whose root is the left child of v (right child of v). v Left subtree of v Right subtree of v Left child of v Right child of v Example of a Binary Tree

2.3 Full m-ary Trees (Definition) n A m-ary tree is FULL iff every vertex has either 0 or m children. (OR every internal vertex has m children). n Examples of full binary trees. Full Tree?YesNoYesNo Yes

Proof: 2.4 Full Tree Theorem n Full Tree theorem: A full m-ary tree with k internal vertices has mk + 1 vertices. Let T=(V,E) be a full m-ary tree, with k internal vertices. Total number of vertices in T Number of vertices that HAVE a parent Number of vertices that DO NOT HAVE a parent = + Q: How many vertices HAVE a parent? 1.Observe for a 2-ary tree with 7 internal vertices 2. Each internal vertex has 2 children

2.5 Leaves-Height Theorem. n Leaves-Height Theorem for Binary Trees: Let T=(V,E) be a binary tree that has t leaves, and height h. Then t 2 h. Proof: (by using induction on the height of the tree) Base Case: h = 0 T has 1 vertex, which is a leaf. t = 1 1 = 2 0 = 2 h Base case is true.

2.5 Leaves-Height Theorem. n Leaves-Height Theorem for Binary Trees: Let T=(V,E) be a binary tree that has t leaves, and height h. Then t 2 h. Proof: (by using induction on the height of the tree) Inductive Case: Assume that t 2 h for h = 0,1,2,…,k (STRONG!) Let T be any binary tree of height k+1. (Need to show t 2 k+1 ) k 1 TLTL TRTR With respect to the root vertex, let the left and right subtrees be T L and T R respectively. Let the number of leaves in T L and T R be t L and t R respectively. (t = t L + t R ) Height of T L and T R are both < k+1. By inductive hypothesis, t L 2 (T L Height) 2 k and t R 2 (T R Height) 2 k. t = t L + t R 2 k + 2 k = 2 k+1.

2.5 Leaves-Height Theorem. n Corollary to the Leaves-Height Theorem: Let T=(V,E) be a binary tree that has t leaves, and height h. Then log 2 t h. Proof: Using leaves-height theorem, we have t 2 h. Taking logarithms on both sides will yield log 2 t log 2 2 h log 2 t h

2.5 Leaves-Height Theorem. IN GENERAL: n Leaves-Height Theorem for m-ary Trees: Let T=(V,E) be a m-ary tree that has t leaves, and height h. Then t m h n Corollary to the Leaves-Height Theorem: Let T=(V,E) be a m-ary tree that has t leaves, and height h. Then log m t h n Proof left as exercise (follows very closely to the proofs shown before)

2.6 Examples n Q: Is there a binary tree that has height 5 and 38 external vertices? n A: No, since 38 > 2 5 which violates the leaves-height theorem.

2.6 Examples n Q: Is there a full binary tree with 10 internal vertices and 13 external vertices? n A: No. Using the full-tree theorem, a binary tree with 10 internal vertices has 21 vertices in total. Therefore there should be = 11 external vertices.

Outline 1.Trees 1.1 Definition of a tree. 1.2 Examples of trees. 1.3 Theorem #1: Tree Characterization 2.Rooted Trees 2.1 Definitions 2.2 Definition: n-ary trees and binary trees. 2.3 Definition: Full n-ary trees 2.4 Theorem #2: Full Tree 2.5 Theorem #3: Leaves-Height 2.6 Examples 3.Spanning Trees 3.1 Motivation 3.2 Definition 3.3 Theorem #4: Spanning Tree 3.4 Minimum Spanning Tree (MST) 3.5 Kruskals Algorithm 3.6 Prims Algorithm

3.1 Spanning Trees. n Example of use is in IP multicasting (studied in networking). n Do a web-search on the keywords IP multicasting spanning tree and more info will be available.

3.1 Spanning Trees. n Layer 2 routing of packets through network switches. n Multiple connections from one switch to the rest of network to increase fault tolerance. n When all links are operational, redundacy in connection occurs. n Network forms a spanning tree so that packets will not be redundantly routed. R n Network will elect a root. n Root will broadcast packets to all other switches. n Each switch will select the best link to use.

3.1 Spanning Trees. n Layer 2 routing of packets through network switches. n Multiple connections from one switch to the rest of network to increase fault tolerance. n When all links are operational, redundacy in connection occurs. n Network forms a spanning tree so that packets will not be redundantly routed. R n Network will elect a root. n Root will broadcast packets to all other switches. n Each switch will select the best link to use.

3.1 Spanning Trees. n Layer 2 routing of packets through network switches. n Multiple connections from one switch to the rest of network to increase fault tolerance. n When all links are operational, redundacy in connection occurs. n Network forms a spanning tree so that packets will not be redundantly routed. R n Network will elect a root. n Root will broadcast packets to all other switches. n Each switch will select the best link to use.

3.1 Spanning Trees. n Layer 2 routing of packets through network switches. n Multiple connections from one switch to the rest of network to increase fault tolerance. n When all links are operational, redundacy in connection occurs. n Network forms a spanning tree so that packets will not be redundantly routed. R n Network will elect a root. n Root will broadcast packets to all other switches. n Each switch will select the best link to use. n When a link goes down, the network reconfigures again.

3.2 Spanning Trees (Definition). n Definition: Let G=(V,E). A spanning tree for G is a subgraph T=(V,E) of G, such that T is a tree and T contains every vertex of G. R

3.3 Spanning Tree theorem. n Spanning Tree theorem: A graph is connected IFF it has a spanning tree. Proof: ( ) Assume that G=(V,E) is connected. We will show that G has a spanning tree. Step 1: Let H = G Step 2: while (H has a circuit C) { Step 2a: Remove an edge from C to form new graph H. Step 2b: Let H = H } Step 3: Output H. 1. Algorithm will terminate because G is finite and there is a finite number of edges to delete

3.4 Minimum Spanning Tree A GH BCD I J K F L E M Let the following graph depict the scenario where the vertices are cities and the weighted edges are distances (km) between the cities. Lets say that the country wants to connect up the cities by building roads between them. The longer the road, the more money it has to spend. How do we connect up the cities and spend the LEAST AMOUNT OF MONEY? Ans: Find the MINIMUM spanning tree.

3.4 Minimum Spanning Tree. n Definition: A weighted graph is a graph where each edge has a number associated with it. G = (V,E), E Z x { {x,y} | x,y V} n The total weight of the graph is the sum of all the weights of the edges in the graph. n A minimum spanning tree (MST) for a weighted graph is a spanning tree that has the least possible total weight compared to all other spanning trees for the graph

3.4 Minimum Spanning Tree. n How to find the minimum spanning tree? –Kruskals Algorithm –Prims Algorithm

3.5 MST: Kruskals Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), E={}, m=0 n 3. while (m < |V| - 1) { –a. Find edge e in E of least weight. –b. E = E - {e} –c. If E {e} does not produce circuit E = E {e} m = m + 1 } n 4. Output T. Idea: To add edges of the smallest weights which do not cause a circuit.

3.5 MST: Kruskals Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), E={}, m=0 n 3. while (m < |V| - 1) { –a. Find edge e in E of least weight. –b. E = E - {e} –c. If E {e} does not produce circuit E = E {e} m = m + 1 } n 4. Output T. A GH BCD I J K F L E M

3.5 MST: Kruskals Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), E={}, m=0 n 3. while (m < |V| - 1) { –a. Find edge e in E of least weight. –b. E = E - {e} –c. If E {e} does not produce circuit E = E {e} m = m + 1 } n 4. Output T. A GH BCD I J K F L E M m=0 |V|-1 = 12

3.5 MST: Kruskals Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), E={}, m=0 n 3. while (m < |V| - 1) { –a. Find edge e in E of least weight. –b. E = E - {e} –c. If E {e} does not produce circuit E = E {e} m = m + 1 } n 4. Output T. A GH BCD I J K F L E M m=1 |V|-1 = 12

3.5 MST: Kruskals Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), E={}, m=0 n 3. while (m < |V| - 1) { –a. Find edge e in E of least weight. –b. E = E - {e} –c. If E {e} does not produce circuit E = E {e} m = m + 1 } n 4. Output T. A GH BCD I J K F L E M m=2 |V|-1 = 12

3.5 MST: Kruskals Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), E={}, m=0 n 3. while (m < |V| - 1) { –a. Find edge e in E of least weight. –b. E = E - {e} –c. If E {e} does not produce circuit E = E {e} m = m + 1 } n 4. Output T. A GH BCD I J K F L E M m=3 |V|-1 = 12

3.5 MST: Kruskals Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), E={}, m=0 n 3. while (m < |V| - 1) { –a. Find edge e in E of least weight. –b. E = E - {e} –c. If E {e} does not produce circuit E = E {e} m = m + 1 } n 4. Output T. A GH BCD I J K F L E M m=4 |V|-1 = 12

3 3.5 MST: Kruskals Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), E={}, m=0 n 3. while (m < |V| - 1) { –a. Find edge e in E of least weight. –b. E = E - {e} –c. If E {e} does not produce circuit E = E {e} m = m + 1 } n 4. Output T. A GH BCD I J K F L E M m=7 |V|-1 = 12

3 3.5 MST: Kruskals Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), E={}, m=0 n 3. while (m < |V| - 1) { –a. Find edge e in E of least weight. –b. E = E - {e} –c. If E {e} does not produce circuit E = E {e} m = m + 1 } n 4. Output T. A GH BCD I J K F L E M m=8 |V|-1 = 12

3 3.5 MST: Kruskals Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), E={}, m=0 n 3. while (m < |V| - 1) { –a. Find edge e in E of least weight. –b. E = E - {e} –c. If E {e} does not produce circuit E = E {e} m = m + 1 } n 4. Output T. A GH BCD I J K F L E M m=9 |V|-1 = 12

3 3.5 MST: Kruskals Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), E={}, m=0 n 3. while (m < |V| - 1) { –a. Find edge e in E of least weight. –b. E = E - {e} –c. If E {e} does not produce circuit E = E {e} m = m + 1 } n 4. Output T. A GH BCD I J K F L E M m=10 |V|-1 = 12 CIRCUIT!!!

3 3.5 MST: Kruskals Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), E={}, m=0 n 3. while (m < |V| - 1) { –a. Find edge e in E of least weight. –b. E = E - {e} –c. If E {e} does not produce circuit E = E {e} m = m + 1 } n 4. Output T. A GH BCD I J K F L E M m=10 |V|-1 = 12

3 3.5 MST: Kruskals Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), E={}, m=0 n 3. while (m < |V| - 1) { –a. Find edge e in E of least weight. –b. E = E - {e} –c. If E {e} does not produce circuit E = E {e} m = m + 1 } n 4. Output T. A GH BCD I J K F L E M m=11 |V|-1 = 12

3 3.5 MST: Kruskals Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), E={}, m=0 n 3. while (m < |V| - 1) { –a. Find edge e in E of least weight. –b. E = E - {e} –c. If E {e} does not produce circuit E = E {e} m = m + 1 } n 4. Output T. A GH BCD I J K F L E M m=12 |V|-1 = 12

3 3.5 MST: Kruskals Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), E={}, m=0 n 3. while (m < |V| - 1) { –a. Find edge e in E of least weight. –b. E = E - {e} –c. If E {e} does not produce circuit E = E {e} m = m + 1 } n 4. Output T. A GH BCD I J K F L E M m=12 |V|-1 = 12 Algorithm Halts. Cost = 39

3.6 MST: Prims Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), V={v}, E={}, m=0, V=V-{v} n 3. while (|V| > 0) { –a. Find an edge e such that e = {x,y}, x in V, y in V. e connects T to some vertex in V. e has least weight of all edges connecting T to a vertex in V. –b. V=V {y}, E = E {e}, V = V - {y} } n 4. Output T. Idea: To grow a spanning tree.

3.6 MST: Prims Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), V={v}, E={}, m=0, V=V-{v} n 3. while (|V| > 0) { –a. Find an edge e such that e = {x,y}, x in V, y in V. e connects T to some vertex in V. e has least weight of all edges connecting T to a vertex in V. –b. V=V {y}, E = E {e}, V = V - {y} } n 4. Output T. A GH BCD I J K F L E M |V| = 12 > 0

3.6 MST: Prims Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), V={v}, E={}, m=0, V=V-{v} n 3. while (|V| > 0) { –a. Find an edge e such that e = {x,y}, x in V, y in V. e connects T to some vertex in V. e has least weight of all edges connecting T to a vertex in V. –b. V=V {y}, E = E {e}, V = V - {y} } n 4. Output T. A GH BCD I J K F L E M |V| = 12 > 0

3.6 MST: Prims Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), V={v}, E={}, m=0, V=V-{v} n 3. while (|V| > 0) { –a. Find an edge e such that e = {x,y}, x in V, y in V. e connects T to some vertex in V. e has least weight of all edges connecting T to a vertex in V. –b. V=V {y}, E = E {e}, V = V - {y} } n 4. Output T. A GH BCD I J K F L E M |V| = 11 > 0

3.6 MST: Prims Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), V={v}, E={}, m=0, V=V-{v} n 3. while (|V| > 0) { –a. Find an edge e such that e = {x,y}, x in V, y in V. e connects T to some vertex in V. e has least weight of all edges connecting T to a vertex in V. –b. V=V {y}, E = E {e}, V = V - {y} } n 4. Output T. A GH BCD I J K F L E M |V| = 11 > 0

3.6 MST: Prims Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), V={v}, E={}, m=0, V=V-{v} n 3. while (|V| > 0) { –a. Find an edge e such that e = {x,y}, x in V, y in V. e connects T to some vertex in V. e has least weight of all edges connecting T to a vertex in V. –b. V=V {y}, E = E {e}, V = V - {y} } n 4. Output T. A GH BCD I J K F L E M |V| = 10 > 0

3.6 MST: Prims Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), V={v}, E={}, m=0, V=V-{v} n 3. while (|V| > 0) { –a. Find an edge e such that e = {x,y}, x in V, y in V. e connects T to some vertex in V. e has least weight of all edges connecting T to a vertex in V. –b. V=V {y}, E = E {e}, V = V - {y} } n 4. Output T. A GH BCD I J K F L E M |V| = 9 > 0

3.6 MST: Prims Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), V={v}, E={}, m=0, V=V-{v} n 3. while (|V| > 0) { –a. Find an edge e such that e = {x,y}, x in V, y in V. e connects T to some vertex in V. e has least weight of all edges connecting T to a vertex in V. –b. V=V {y}, E = E {e}, V = V - {y} } n 4. Output T. A GH BCD I J K F L E M |V| = 8 > 0

3.6 MST: Prims Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), V={v}, E={}, m=0, V=V-{v} n 3. while (|V| > 0) { –a. Find an edge e such that e = {x,y}, x in V, y in V. e connects T to some vertex in V. e has least weight of all edges connecting T to a vertex in V. –b. V=V {y}, E = E {e}, V = V - {y} } n 4. Output T. A GH BCD I J K F L E M |V| = 7 > 0

3.6 MST: Prims Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), V={v}, E={}, m=0, V=V-{v} n 3. while (|V| > 0) { –a. Find an edge e such that e = {x,y}, x in V, y in V. e connects T to some vertex in V. e has least weight of all edges connecting T to a vertex in V. –b. V=V {y}, E = E {e}, V = V - {y} } n 4. Output T. A GH BCD I J K F L E M |V| = 6 > 0

3.6 MST: Prims Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), V={v}, E={}, m=0, V=V-{v} n 3. while (|V| > 0) { –a. Find an edge e such that e = {x,y}, x in V, y in V. e connects T to some vertex in V. e has least weight of all edges connecting T to a vertex in V. –b. V=V {y}, E = E {e}, V = V - {y} } n 4. Output T. A GH BCD I J K F L E M |V| = 5 > 0

3.6 MST: Prims Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), V={v}, E={}, m=0, V=V-{v} n 3. while (|V| > 0) { –a. Find an edge e such that e = {x,y}, x in V, y in V. e connects T to some vertex in V. e has least weight of all edges connecting T to a vertex in V. –b. V=V {y}, E = E {e}, V = V - {y} } n 4. Output T. A GH BCD I J K F L E M |V| = 4 > 0

3.6 MST: Prims Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), V={v}, E={}, m=0, V=V-{v} n 3. while (|V| > 0) { –a. Find an edge e such that e = {x,y}, x in V, y in V. e connects T to some vertex in V. e has least weight of all edges connecting T to a vertex in V. –b. V=V {y}, E = E {e}, V = V - {y} } n 4. Output T. A GH BCD I J K F L E M |V| = 3 > 0

3.6 MST: Prims Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), V={v}, E={}, m=0, V=V-{v} n 3. while (|V| > 0) { –a. Find an edge e such that e = {x,y}, x in V, y in V. e connects T to some vertex in V. e has least weight of all edges connecting T to a vertex in V. –b. V=V {y}, E = E {e}, V = V - {y} } n 4. Output T. A GH BCD I J K F L E M |V| = 2 > 0

3.6 MST: Prims Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), V={v}, E={}, m=0, V=V-{v} n 3. while (|V| > 0) { –a. Find an edge e such that e = {x,y}, x in V, y in V. e connects T to some vertex in V. e has least weight of all edges connecting T to a vertex in V. –b. V=V {y}, E = E {e}, V = V - {y} } n 4. Output T. A GH BCD I J K F L E M |V| = 1 > 0

3.6 MST: Prims Algorithm n 1. Input: G=(V,E) n 2. Let T=(V,E), V={v}, E={}, m=0, V=V-{v} n 3. while (|V| > 0) { –a. Find an edge e such that e = {x,y}, x in V, y in V. e connects T to some vertex in V. e has least weight of all edges connecting T to a vertex in V. –b. V=V {y}, E = E {e}, V = V - {y} } n 4. Output T. A GH BCD I J K F L E M |V| = 0 Algorithm Halts. Cost = 39

Different output possible 3 A GH BCD I J K F L E M A GH BCD I J K F L E M Kruskals Algorithm Prims Algorithm Cost of Tree = 39