Minimum Spanning Tree Sarah Brubaker Tuesday 4/22/8.

Slides:



Advertisements
Similar presentations
Spanning Trees. Prims MST Algorithm Algorithm ( this is also greedy) Select an arbitrary vertex to start the tree, while there are fringe vertices: 1)select.
Advertisements

Decision Maths Networks Kruskals Algorithm Wiltshire Networks A Network is a weighted graph, which just means there is a number associated with each.
Greedy Algorithms Pasi Fränti Greedy algorithm 1.Coin problem 2.Minimum spanning tree 3.Generalized knapsack problem 4.Traveling salesman problem.
Chapter 15 Graph Theory © 2008 Pearson Addison-Wesley. All rights reserved.
MINIMAL CONNECTOR PROBLEMS Problem: A cable TV company is installing a system of cables to connect all the towns in a region. The numbers in the network.
Graphs CS-240/341. Graphs Used for representing many-to-many relationships –can take two forms directed (digraph) - a finite set of elements called vertices.
Discussion #36 Spanning Trees
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Is the following graph Hamiltonian- connected from vertex v? a). Yes b). No c). I have absolutely no idea v.
Design and Analysis of Algorithms Minimum Spanning trees
More Chapter 7: Greedy Algorithms Kruskal’s Minimum Spanning Tree Algorithm.
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.
Chapter 15 Graph Theory © 2008 Pearson Addison-Wesley. All rights reserved.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
WEIGHTED GRAPHS. Weighted Graphs zGraph G = (V,E) such that there are weights/costs associated with each edge Õw((a,b)): cost of edge (a,b) Õrepresentation:
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Greedy methods Prudence Wong
ADA: 10. MSTs1 Objective o look at two algorithms for finding mimimum spanning trees (MSTs) over graphs Prim's algorithm, Kruskal's algorithm Algorithm.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Minimum spanning trees Aims: To know the terms: tree, spanning tree, minimum spanning tree. To understand that a minimum spanning tree connects a network.
Graph Partitioning Problem Kernighan and Lin Algorithm
Chapter 4 sections 1 and 2.  Fig. 1  Not connected  All vertices are even.  Fig. 2  Connected  All vertices are even.
Spanning Trees Introduction to Spanning Trees AQR MRS. BANKS Original Source: Prof. Roger Crawfis from Ohio State University.
Minimum Spanning Trees Prof. Sin-Min Lee Dept. of Computer Science, San Jose State University.
Spanning Trees. A spanning tree for a connected, undirected graph G is a graph S consisting of the nodes of G together with enough edges of G such that:
MCA 202: Discrete Structures Instructor Neelima Gupta
Minimum- Spanning Trees
By Meli & Amy & Meggie & Bex. What is route inspection hmmmm??? Objective: Is to go along every single edge and end up back to where you started from.
Prims Algorithm for finding a minimum spanning tree
Minimum Spanning Trees Text Read Weiss, §9.5 Prim’s Algorithm Weiss §9.5.1 Similar to Dijkstra’s Algorithm Kruskal’s Algorithm Weiss §9.5.2 Focuses on.
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
Representing Graphs Depth First Search Breadth First Search Graph Searching Algorithms.
Kruskal’s Algorithm for Computing MSTs Section 9.2.
Graphs Chapter 20.
A vertex u is reachable from vertex v iff there is a path from v to u.
COMP108 Algorithmic Foundations Greedy methods
May 12th – Minimum Spanning Trees
Minimum Spanning Tree Chapter 13.6.
Spanning Trees.
Lecture 12 Graph Algorithms
Kruskal’s Algorithm Elaicca Ronna Ordoña. A cable company want to connect five villages to their network which currently extends to the market town of.
Minimum Spanning Trees and Shortest Paths
CISC 235: Topic 10 Graph Algorithms.
Jan 2007.
CS120 Graphs.
Graph Algorithm.
CSCE350 Algorithms and Data Structure
Spanning Trees.
Chapter 7: Greedy Algorithms
CSE373: Data Structures & Algorithms Lecture 12: Minimum Spanning Trees Catie Baker Spring 2015.
CSE373: Data Structures & Algorithms Lecture 20: Minimum Spanning Trees Linda Shapiro Spring 2016.
Minimum Spanning Trees
CSE 373 Data Structures and Algorithms
Spanning Trees.
Kruskal’s Algorithm for finding a minimum spanning tree
Chapter 9: Graphs Basic Concepts
Graphs Part 2 Adjacency Matrix
Example A cable company want to connect five villages to their network which currently extends to the market town of Avonford. What is the minimum.
Minimum spanning trees
AB AC AD AE AF 5 ways If you used AB, then, there would be 4 remaining ODD vertices (C, D, E and F) CD CE CF 3 ways If you used CD, then, there.
Minimum spanning trees
Networks Kruskal’s Algorithm
CSE 373: Data Structures and Algorithms
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Minimum Spanning Trees (MSTs)
Kruskal’s Algorithm AQR.
CSE 373: Data Structures and Algorithms
Graph Search in C++ Andrew Lindsay.
Lecture 11 Graph Algorithms
Chapter 9: Graphs Basic Concepts
Homework Solutions.
Presentation transcript:

Minimum Spanning Tree Sarah Brubaker Tuesday 4/22/8

Minimum Spanning Tree Input: graph G with weights on the edges Output: connected sub graph G’ of G that includes all the vertices of G, of minimum total weight

Exhaustive Search List all connected sub-graphs of G Return sub-graph with least weight Number of vertices, N, and number of edges, M O(m n-1 )

Greedy Algorithm Start with a graph containing just the vertices, G’={V,Ø} Add edges with the least weight until the graph is connected but no cycles are created To do this: – Order the edges in increasing weight – While the graph is not connected, add an edge – End when all vertices are connected

Greedy Algorithm - Example Initial Graph:List of Edges: EdgeWeight AB1 AF5 BC8 BD4 BF5 CD2 CF3 DE10 DF1 EF4

Greedy Algorithm - Example Graph:Sorted List of Edges: EdgeWeight AB1 DF1 CD2 CF3 BD4 EF4 AF5 BF5 BC8 DE10 Start with G’={V,Ø} and sorted list of edges

Greedy Algorithm - Example Graph:Sorted List of Edges: EdgeWeight AB1 DF1 CD2 CF3 BD4 EF4 AF5 BF5 BC8 DE10 Add edge from list to graph s.t. no cycles are created Remove edge from list

Greedy Algorithm - Example Graph:Sorted List of Edges: EdgeWeight AB1 DF1 CD2 CF3 BD4 EF4 AF5 BF5 BC8 DE10 Add edge from list to graph s.t. no cycles are created Remove edge from list

Greedy Algorithm - Example Graph:Sorted List of Edges: EdgeWeight CF3 BD4 EF4 AF5 BF5 BC8 DE10 Add edge from list to graph s.t. no cycles are created Remove edge from list Check for cycles using Depth First Search starting at a vertex in the added edge: Start at C C-> D -> F -> C C gets visited twice => a cycle exists and CF should not be added to the graph

Greedy Algorithm - Example Graph:Sorted List of Edges: EdgeWeight BD4 EF4 AF5 BF5 BC8 DE10 Add edge from list to graph s.t. no cycles are created Remove edge from list End when all vertices can be visited (graph is connected) Check for cycles using Depth First Search starting at a vertex in the added edge: Start at B B ->D ->C -> F -> A If all vertices are visited by DFS, then the graph is connected and we are done

Greedy Algorithm - Example Graph:Sorted List of Edges: EdgeWeight EF4 AF5 BF5 BC8 DE10 Add edge from list to graph s.t. no cycles are created Remove edge from list End when all vertices can be visited (graph is connected) Check for cycles using Depth First Search starting at a vertex in the added edge: Start at E E -> F -> D -> B -> A ->C All vertices were visited and there were no cycles => we have found a minimum spanning tree with weight 12.

Greedy Algorithm- Psuedocode Given G = (V, E) G’ <- (V,Ø) While G’ is not connected – Add e Є E to G’ s.t. G’ is acyclic and e is minimum – Remove e from E

Greedy Algorithm – Run Time Initialization – constant While loop – O(n-1) – Connected graph has n-1 edges – Must add n-1 edges to the graph for it to be connected Find a minimum e Є E – O(m) Make sure G’ is acyclic – O(2n) – DFS is O(m+n)<O(2n) where m<=n-1 Test connectivity of G’ – O(n) – Can use DFS; could be done in same step as testing acyclicity Remove e from E - constant Total Runtime: O(n*(m+2n+n)) ~ O(nm+ n 2 ) -> POLYNOMIAL

Error? Let X be any subset of the vertices of G, and let edge e be the smallest edge connecting X to G-X. Then e is part of the minimum spanning tree.

Error? 1.T does not contain e and is a spanning tree 2.e is smallest edge connecting X = {C,D} to G-X ={A,B,F,E} 3.Adding e creates a cycle in T 4.Another spanning tree exists, T 2 = T+e-f, where f is another edge that could connect X to G-x 5.Because e < f, T was not the MST and e must be part of the MST 1 2 4

Error? In the greedy algorithm, the edge added was always the smallest. Because the smallest edge to connect two parts of the original graph must be included, each edge added must be a part of the final minimum spanning tree. In this case, the greedy algorithm is always correct (but we know this is not the case for ALL greedy algorithms).