Minimal Spanning Trees – Page 1CSCI 1900 – Discrete Structures CSCI 1900 Discrete Structures Minimal Spanning Trees Reading: Kolman, Section 7.5.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Weighted graphs Example Consider the following graph, where nodes represent cities, and edges show if there is a direct flight between each pair of cities.
10.4 Spanning Trees. Def Def: Let G be a simple graph. A spanning tree of G is a subgraph of G that is a tree containing every vertex of G See handout.
3.3 Spanning Trees Tucker, Applied Combinatorics, Section 3.3, by Patti Bodkin and Tamsen Hunter.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
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.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Spanning Trees.
Spanning Trees. 2 Spanning trees Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Is the following graph Hamiltonian- connected from vertex v? a). Yes b). No c). I have absolutely no idea v.
3/29/05Tucker, Sec Applied Combinatorics, 4th Ed. Alan Tucker Section 4.2 Minimal Spanning Trees Prepared by Amanda Dargie and Michele Fretta.
Spanning Trees. Spanning trees Suppose you have a connected undirected graph –Connected: every node is reachable from every other node –Undirected: edges.
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.
Minimum spanning tree Prof Amir Geva Eitan Netzer.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
Chapter 2 Graph Algorithms.
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
COSC 2007 Data Structures II Chapter 14 Graphs III.
Foundations of Discrete Mathematics
Spanning Trees Introduction to Spanning Trees AQR MRS. BANKS Original Source: Prof. Roger Crawfis from Ohio State University.
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
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.
Minimum spanning trees Aims: To know the terms: tree, spanning tree, minimum spanning tree. To understand that a minimum spanning tree connects a network.
Spanning Trees CSIT 402 Data Structures II 1. 2 Two Algorithms Prim: (build tree incrementally) – Pick lower cost edge connected to known (incomplete)
Fundamental Data Structures and Algorithms (Spring ’05) Recitation Notes: Graphs Slides prepared by Uri Dekel, Based on recitation.
Introduction to Graph Theory
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.
Data Structures CSCI 132, Spring 2014 Lecture 38 Graphs
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Graphs Upon completion you will be able to:
Trees Thm 2.1. (Cayley 1889) There are nn-2 different labeled trees
MA/CSSE 473 Day 34 MST details: Kruskal's Algorithm Prim's Algorithm.
Prims Algorithm for finding a minimum spanning tree
Lecture 19 Minimal Spanning Trees CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
COMPSCI 102 Introduction to Discrete Mathematics.
Lecture 12 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
MATRIX FORM OF PRIM’S ALGORITHM. This network may be described using a Distance Matrix.
Applied Discrete Mathematics Week 15: Trees
COMP108 Algorithmic Foundations Greedy methods
Minimum Spanning Tree Chapter 13.6.
Discrete Mathematicsq
Lecture 12 Algorithm Analysis
Short paths and spanning trees
Graph Algorithm.
Spanning Trees.
Connected Components Minimum Spanning Tree
Spanning Trees.
Chapter 23 Minimum Spanning Tree
Graph Operations And Representation
CSCI2100 Data Structures Tutorial
And the Final Subject is…
The Greedy Approach Young CS 530 Adv. Algo. Greedy.
Lecture 12 Algorithm Analysis
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Section 13.4 Trees.
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Presentation transcript:

Minimal Spanning Trees – Page 1CSCI 1900 – Discrete Structures CSCI 1900 Discrete Structures Minimal Spanning Trees Reading: Kolman, Section 7.5

Minimal Spanning Trees – Page 2CSCI 1900 – Discrete Structures In-Class Exercise A small startup airline wants to provide service to the 5 cities in the table to the right. Allowing for multiple connecting flights, determine all of the direct flights that would be needed in order to service all five cities. City 1City 2Mileage ClevelandPhiladelphia400 ClevelandDetroit200 ClevelandChicago350 ClevelandPittsburg150 PhiladelphiaDetroit600 PhiladelphiaChicago700 PhiladelphiaPittsburg300 DetroitChicago300 DetroitPittsburg300 ChicagoPittsburg450 Source:

Minimal Spanning Trees – Page 3CSCI 1900 – Discrete Structures Undirected Graph If you recall from our discussion on types of relations, a symmetric relation is one that for every relation (a,b) that is contained in R, the relation (b,a) is also in R. If the relation is represented with a matrix, this means that the matrix is symmetric across the main diagonal. In the digraph of a symmetric relation, every edge is bidirectional, i.e., there is no defined direction.

Minimal Spanning Trees – Page 4CSCI 1900 – Discrete Structures Connected Relation A relation is connected if for every a and b in R, there is a path from a to b. It is easier to see a connected relation using a digraph than it is to describe in using words. A B D C E Connected A B D C E Not Connected

Minimal Spanning Trees – Page 5CSCI 1900 – Discrete Structures Spanning Tree Textbook definition: “If R is a symmetric, connected relation on a set A, we say that a tree T on A is a spanning tree for R if T is a tree with exactly the same vertices as R and which can be obtained from R by deleting some edges of R.” p. 275 Basically, a undirected spanning tree is one that connects all n elements of A with n-1 edges. To make a cycle connecting n elements, more than n-1 edges will be needed. Therefore, there are no cycles.

Minimal Spanning Trees – Page 6CSCI 1900 – Discrete Structures Weighted Graph In the past, we have represented a undirected graph with unlabeled edges. It can also be represented with a symmetric binary matrix M T = A B D C

Minimal Spanning Trees – Page 7CSCI 1900 – Discrete Structures Weighted Graph (continued) By giving the edges a numeric value indicating some parameter in the relation between two vertices, we have created a weighted tree. A B D C

Minimal Spanning Trees – Page 8CSCI 1900 – Discrete Structures Weighted Graph (continued) We can still use matrix notation to represent a weighted graph. Replace the 1’s used to represent an edge with the edge’s weight. A 0 indicates no edge M T =

Minimal Spanning Trees – Page 9CSCI 1900 – Discrete Structures Back to In-Class Exercise (Not drawn to scale) Philadelphia Pittsburg Chicago Cleveland Detroit

Minimal Spanning Trees – Page 10CSCI 1900 – Discrete Structures Minimal Spanning Tree Assume T represents a spanning tree for an undirected graph. The total weight of the spanning tree T is the sum of all of the weights of all of the edges of T. The one(s) with the minimum total weight are called the minimal spanning tree(s). As suggested by the “(s)” in the above definition, there may be a number of minimal spanning trees for a particular undirected graph with the same total weight.

Minimal Spanning Trees – Page 11CSCI 1900 – Discrete Structures Algorithms for Determining the Minimal Spanning Tree There are two algorithms presented in our textbook for determining the minimal spanning tree of an undirected graph that is connected and weighted. –Prim’s Algorithm: process of stepping from vertex to vertex –Kruskal’s Algoritm: searching through edges for minimum weights

Minimal Spanning Trees – Page 12CSCI 1900 – Discrete Structures Prim’s Algorithm From textbook, p. 281 Let R be a symmetric, connected relation with n vertices. 1.Choose a vertex v 1 of R. Let V = {v 1 } and E = { }. 2.Choose a nearest neighbor v i of V that is adjacent to v j, v j  V, and for which the edge (v i, v j ) does not form a cycle with members of E. Add v i to V and add (v i, v j ) to E. 3.Repeat Step 2 until |E| = n – 1. Then V contains all n vertices of R, and E contains the edges of a minimal spanning tree for R.

Minimal Spanning Trees – Page 13CSCI 1900 – Discrete Structures Prim’s Algorithm in English The goal is to one at a time include a new vertex by adding a new edge without creating a cycle Pick any vertex to start. From it, pick the edge with the lowest weight. As you add vertices, you will add possible edges to follow to new vertices. Pick the edge with the lowest weight to go to a new vertex without creating a cycle.

Minimal Spanning Trees – Page 14CSCI 1900 – Discrete Structures In-Class Exercise (1 st edge) Pick any starting point: Detroit. Pick edge with lowest weight: 200 (Cleveland) Cleveland Detroit 200

Minimal Spanning Trees – Page 15CSCI 1900 – Discrete Structures In-Class Exercise (2 nd edge) Pick any edge connected to Cleveland or Detroit that doesn’t create a cycle: 150 (Pittsburg) Pittsburg Cleveland Detroit

Minimal Spanning Trees – Page 16CSCI 1900 – Discrete Structures In-Class Exercise (3 rd edge) Pick any edge connected to Cleveland, Detroit, or Pittsburg that doesn’t create a cycle: 300 (Philadelphia) Philadelphia Pittsburg Cleveland Detroit

Minimal Spanning Trees – Page 17CSCI 1900 – Discrete Structures In-Class Exercise (4 th edge) Pick any edge connected to Cleveland, Detroit, Pittsburg, or Philadelphia that doesn’t create a cycle: 300 (Chicago) This gives us 4 edges! Chicago 300 Philadelphia Pittsburg Cleveland Detroit

Minimal Spanning Trees – Page 18CSCI 1900 – Discrete Structures Kruskal’s Algorithm From textbook, p. 284 Let R be a symmetric, connected relation with n vertices and let S = {e 1, e 2, e 3, …e k } be the set of all weighted edges of R. 1.Choose an edge e 1 in S of least weight. Let E = {e 1 }. Replace S with S – {e 1 }. 2.Select an edge e i in S of least weight that will not make a cycle with members of E. Replace E with E  {e i } and S with S – {e i }. 3.Repeat Step 2 until |E| = n – 1.

Minimal Spanning Trees – Page 19CSCI 1900 – Discrete Structures Kruskal’s Algorithm in English The goal is to one at a time include a new edge without creating a cycle. Start by picking the edge with the lowest weight. Continue to pick new edges without creating a cycle. Edges do not necessarily have to be connected. Stop when you have n-1 edges.

Minimal Spanning Trees – Page 20CSCI 1900 – Discrete Structures In-Class Exercise (1 st edge) First edge picked is lowest value of 150 (Cleveland to Pittsburg) Pittsburg Cleveland 150

Minimal Spanning Trees – Page 21CSCI 1900 – Discrete Structures In-Class Exercise (2 nd edge) Next lowest edge is 200 (Cleveland to Detroit) Pittsburg Cleveland Detroit

Minimal Spanning Trees – Page 22CSCI 1900 – Discrete Structures In-Class Exercise (3 rd edge) There are a few edges of 300, but Detroit to Pittsburg cannot be selected because it would create a cycle. We go with Pittsburg to Philadelphia. Philadelphia Pittsburg Cleveland Detroit

Minimal Spanning Trees – Page 23CSCI 1900 – Discrete Structures In-Class Exercise (4 th edge) The next lowest edge that doesn’t create a cycle is 300 edge from Detroit to Chicago. This is the 4 th edge! Philadelphia Pittsburg Cleveland Detroit Chicago 300