CS2420: Lecture 40 Vladimir Kulyukin Computer Science Department Utah State University.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

CS1022 Computer Programming & Principles
Minimum Spanning Tree Sarah Brubaker Tuesday 4/22/8.
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.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Chapter 15 Graph Theory © 2008 Pearson Addison-Wesley. All rights reserved.
CS2420: Lecture 19 Vladimir Kulyukin Computer Science Department Utah State University.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
CS2420: Lecture 43 Vladimir Kulyukin Computer Science Department Utah State University.
CS2420: Lecture 37 Vladimir Kulyukin Computer Science Department Utah State University.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Graphs & Graph Algorithms 2 Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Vladimir Kulyukin Computer Science Department Utah State University
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
More Chapter 7: Greedy Algorithms Kruskal’s Minimum Spanning Tree Algorithm.
Chapter 9: Graphs Spanning Trees Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
CS2420: Lecture 36 Vladimir Kulyukin Computer Science Department Utah State University.
Dynamic Sets and Data Structures Over the course of an algorithm’s execution, an algorithm may maintain a dynamic set of objects The algorithm will perform.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
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.
TECH Computer Science Graph Optimization Problems and Greedy Algorithms Greedy Algorithms  // Make the best choice now! Optimization Problems  Minimizing.
Graphs CS 400/600 – Data Structures. Graphs2 Graphs  Used to represent all kinds of problems Networks and routing State diagrams Flow and capacity.
Design and Analysis of Computer Algorithm September 10, Design and Analysis of Computer Algorithm Lecture 5-2 Pradondet Nilagupta Department of Computer.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
ADA: 10. MSTs1 Objective o look at two algorithms for finding mimimum spanning trees (MSTs) over graphs Prim's algorithm, Kruskal's algorithm Algorithm.
COSC 2007 Data Structures II Chapter 14 Graphs III.
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.
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
1 Minimum Spanning Trees (some material adapted from slides by Peter Lee, Ananda Guna, Bettina Speckmann)
Lecture19: Graph III Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
1 Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that are: b feasible b locally optimal.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
SPANNING TREES Lecture 21 CS2110 – Fall Nate Foster is out of town. NO 3-4pm office hours today!
Minimum- Spanning 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.
WEEK 12 Graphs IV Minimum Spanning Tree Algorithms.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
Algorithm Design and Analysis June 11, Algorithm Design and Analysis Pradondet Nilagupta Department of Computer Engineering This lecture note.
Spanning Trees Alyce Brady CS 510: Computer Algorithms.
Graph Search Applications, Minimum Spanning Tree
CS1022 Computer Programming & Principles
COMP108 Algorithmic Foundations Greedy methods
Greedy Technique.
May 12th – Minimum Spanning Trees
Minimum Spanning Tree Chapter 13.6.
Minimum Spanning Trees and Shortest Paths
I206: Lecture 15: Graphs Marti Hearst Spring 2012.
CSCE350 Algorithms and Data Structure
Minimum Spanning Tree.
Connected Components Minimum Spanning Tree
Graphs Chapter 13.
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.
CSE 373 Data Structures and Algorithms
Graphs.
Outline This topic covers Prim’s algorithm:
CSE332: Data Abstractions Lecture 18: Minimum Spanning Trees
CSE 373: Data Structures and Algorithms
Weighted Graphs & Shortest Paths
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Chapter 9: Graphs Spanning Trees
Presentation transcript:

CS2420: Lecture 40 Vladimir Kulyukin Computer Science Department Utah State University

Outline Graph Algorithms (Chapter 9)

Spanning Trees An edge e in G is redundant if, after the removal of e, G remains connected. A spanning tree of G is a tree (acyclic graph) that contains all vertices of G and preserves G’s connectivity without any redundant edges.

Spanning Tree A spanning tree of a connected graph is its connected acyclic sub-graph (a tree) that contains all vertices of the graph and preserves the graph’s connectivity. In a weighted connected graph, the weight of a spanning tree is defined as the sum of the tree’s edges. A minimal (minimum) spanning tree of a weighted connected graph is a spanning tree of the smallest weight.

Spanning Tree: Example A BC D A B C D

Spanning Trees: Examples AB CD Original Graph AB DC Tree T 1 Weight(T 1 ) = 6 AB CD Tree T 2 Weight(T 2 ) = 9 AB CD Tree T 3 Weight(T 3 ) = 8

Min Spanning Tree Construction Construct a minimum spanning tree by expanding it with one vertex at each iteration. The initial tree consists of one vertex, i.e. the root. On each iteration, the tree so far is expanded by attaching to it the nearest vertex. Stop when all the vertices are included.

Min Spanning Tree Construction: Example AB CD Original Graph AB D C 1 2 Step 1 AB 1 Step 2 AB D Step 3

Min Spanning Tree Construction: Prim’s Algorithm G = (V, E) is a weighted connected graph Input: G = (V, E). Output: E T, the set of edges composing a minimum spanning tree.

Prim’s Algorithm: Insight v2v2 v3v3 v4v4 u* u is the vertex we have reached; next we choose the vertex closest to u* by comparing the weights: w 1, w 2, w 3, and w 4. v1v1 w1w1 w2w2 w3w3 w4w4

Prim’s Algorithm: Update After v is reached, two operations must be performed: –Mark v as visited, i.e. move it into V T ; –For each remaining vertex v not in V T and connected to u by a shorter edge than v’s current weight label, update v’s weight label (V.Wght) by the weight of (u, v) and set v’s previous label (V.Prev) to u.

Prim’s Algorithm: Example BC ADF E TreeRemaining Vertices NULL,,,,,,,,,,,,,

Prim’s Algorithm: Example BC A D F E

BC A D F E

BC A D F E

BC A D F E

BC A D F E

Prim’s Algorithm: Result Spanning Tree BC A D F E

Prim’s Algorithm: Implementation A vertex v has four labels: –1) The vertex’s name, i.e., V; –2) The name of the vertex U from which V was reached (V.Prev); –3) The weight of (u, v) (V.Wght). Remember V.Wght = weight(u,v); –4) Visitation status of V (V.Visisted); this is a boolean variable, initially false, and set to true when V is visited. Unreached vertices have NULL as the value of V.Prev and INF as the value of V.Wght.

Prim’s Algorithm: Implementation We assume that we have implemented a dynamic priority queue data structure (DynamicPriorityQueue). If Q is a dynamic priority queue, then we can perform the following operations on it: –Q.Insert(v); // inserts an element v into Q; –Q.UpdatePriority(v); // moves v up or down the minimal heap; –Q.Pop(); // removes the minimal element; –Q.Push(v); // inserts v into Q.