CSC 380: Design and Analysis of Algorithms

Slides:



Advertisements
Similar presentations
Chapter 23 Minimum Spanning Tree
Advertisements

Introduction to Algorithms Greedy Algorithms
Types of Algorithms.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
1 Spanning Trees Lecture 20 CS2110 – Spring
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
1 Greedy Algorithms. 2 2 A short list of categories Algorithm types we will consider include: Simple recursive algorithms Backtracking algorithms Divide.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
Design and Analysis of Algorithms Minimum Spanning trees
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 in Graph - Week Problem: Laying Telephone Wire Central office.
Minimum Spanning Tree Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Lecture 23. Greedy Algorithms
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
SPANNING TREES Lecture 21 CS2110 – Spring
Minimum Spanning Trees
Dr. Naveed Ahmad Assistant Professor Department of Computer Science University of Peshawar.
COSC 2007 Data Structures II Chapter 14 Graphs III.
UNC Chapel Hill Lin/Foskey/Manocha Minimum Spanning Trees Problem: Connect a set of nodes by a network of minimal total length Some applications: –Communication.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
Prims’ spanning tree algorithm Given: connected graph (V, E) (sets of vertices and edges) V1= {an arbitrary node of V}; E1= {}; //inv: (V1, E1) is a tree,
Minimum spanning trees Aims: To know the terms: tree, spanning tree, minimum spanning tree. To understand that a minimum spanning tree connects a network.
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
Minimal Spanning Tree Problems in What is a minimal spanning tree An MST is a tree (set of edges) that connects all nodes in a graph, using.
Minimum Spanning Trees CS 146 Prof. Sin-Min Lee Regina Wang.
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.
SPANNING TREES Lecture 20 CS2110 – Fall Spanning Trees  Definitions  Minimum spanning trees  3 greedy algorithms (incl. Kruskal’s & Prim’s)
SPANNING TREES Lecture 21 CS2110 – Fall Nate Foster is out of town. NO 3-4pm office hours today!
Lecture 19 Minimal Spanning Trees CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
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.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
SPANNING TREES Lecture 21 CS2110 – Spring
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
Greedy Algorithms.
Minimum Spanning Trees
COMP108 Algorithmic Foundations Greedy methods
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
Greedy Technique.
Minimum Spanning Tree Chapter 13.6.
Department of Computer Science
Lecture 22 Minimum Spanning Tree
Spanning Trees Lecture 21 CS2110 – Fall 2016.
Short paths and spanning trees
Data Structures & Algorithms Graphs
Autumn 2016 Lecture 11 Minimum Spanning Trees (Part II)
CSCE350 Algorithms and Data Structure
Minimum Spanning Tree.
Minimum Spanning Trees
Connected Components Minimum Spanning Tree
Minimum Spanning Tree.
Types of Algorithms.
CSE373: Data Structures & Algorithms Lecture 12: Minimum Spanning Trees Catie Baker Spring 2015.
CSE 373 Data Structures and Algorithms
Shortest Path.
Advanced Analysis of Algorithms
Autumn 2015 Lecture 10 Minimum Spanning Trees
Graph Searching.
CSCI2100 Data Structures Tutorial
CSC 380: Design and Analysis of Algorithms
Minimum Spanning Tree.
CSE 373: Data Structures and Algorithms
Types of Algorithms.
CSC 380: Design and Analysis of Algorithms
Spanning Trees Lecture 20 CS2110 – Spring 2015.
Prim’s algorithm for minimum spanning trees
Prims’ spanning tree algorithm
Minimum Spanning Trees
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

CSC 380: Design and Analysis of Algorithms Dr. Curry Guinn

Quick Info Dr. Curry Guinn CIS 2015 guinnc@uncw.edu www.uncw.edu/people/guinnc 962-7937 Office Hours: MWF: 10:00am-11:00m and by appointment

Outline of today Closest Points Greedy Algorithms Making change Minimum spanning tree Prim Kruskal

Optimization problems An optimization problem is one in which you want to find, not just a solution, but the best solution A “greedy algorithm” sometimes works well for optimization problems A greedy algorithm works in phases. At each phase: You take the best you can get right now, without regard for future consequences You hope that by choosing a local optimum at each step, you will end up at a global optimum 2

Example: Counting money Suppose you want to count out a certain amount of money, using the fewest possible bills and coins A greedy algorithm would do this would be: At each step, take the largest possible bill or coin that does not overshoot Example: To make $6.39, you can choose: a $5 bill a $1 bill, to make $6 a 25¢ coin, to make $6.25 A 10¢ coin, to make $6.35 four 1¢ coins, to make $6.39 For US money, the greedy algorithm always gives the optimum solution 3

A failure of the greedy algorithm In some (fictional) monetary system, “krons” come in 1 kron, 7 kron, and 10 kron coins Using a greedy algorithm to count out 15 krons, you would get A 10 kron piece Five 1 kron pieces, for a total of 15 krons This requires six coins A better solution would be to use two 7 kron pieces and one 1 kron piece This only requires three coins The greedy algorithm results in a solution, but not in an optimal solution 4

Other greedy algorithms Prim’s algorithm for finding a minimum-cost spanning tree Always takes the lowest-cost edge between nodes in the spanning tree and nodes not yet in the spanning tree Kruskal’s algorithm for finding a minimum-cost spanning tree Always tries the lowest-cost remaining edge Dijkstra’s algorithm for finding the shortest path in a graph Always takes the shortest edge connecting a known node to an unknown node

Minimum spanning tree Tree: a connected, directed acyclic graph Spanning tree: a subgraph of a graph, which meets the constraints to be a tree (connected, acyclic) and connects every vertex of the original graph Minimum spanning tree: a spanning tree with weight less than or equal to any other spanning tree for the given graph

Min. span. tree applications Consider a cable TV company laying cable to a new neighborhood... Each house is a vertex. Connections between houses have a cost based on length. What is the minimum layout that connects all the houses?

Minimum Cost Spanning Trees Spanning Tree Definition Consider a connected, undirected graph G=(V, E). A spanning tree T = (V’, E’) of G is a subgraph of G with the following properties: V’ = V T is connected T is acyclic

Minimum Cost Spanning Trees Total Cost Definition The total cost of an edge-weighted undirected graph is the sum of the weights on all the edges in that graph

Minimum Cost Spanning Trees Minimum Spanning Tree Definition Consider an edge-weighted, undirected, connected graph G=(V, E), where c(v, w) represents the weight on edge {v, w}E. The minimum spanning tree of G is the spanning tree T=(V, E’) that has the smallest total cost,

Minimum Cost Spanning Trees Prim’s Algorithm Constructs the minimum-cost spanning tree of a graph by selecting edges from the graph one-by-one and adding those edges to the spanning tree At each step, select an edge with the smallest edge weight that connects the tree to a vertex not yet in the tree

2 V1 V2 V1 V2 4 1 3 10 1 2 7 V3 V3 V4 V5 V4 V5 8 4 6 5 1 V6 V7 V6 V7

2 2 V1 V2 V1 V2 4 1 3 10 1 2 7 V3 V3 V4 V5 V4 V5 8 4 6 5 1 V6 V7 V6 V7

2 2 V1 V2 V1 V2 4 1 3 10 1 2 7 2 V3 V3 V4 V5 V4 V5 8 4 6 5 1 V6 V7 V6 V7

2 2 V1 V2 V1 V2 4 1 3 10 1 2 7 2 V3 V3 V4 V5 V4 V5 8 4 4 6 5 1 V6 V7 V6 V7

2 2 V1 V2 V1 V2 4 1 3 10 1 2 7 2 V3 V3 V4 V5 V4 V5 8 4 4 6 5 1 1 V6 V7 V6 V7

2 2 V1 V2 V1 V2 4 1 3 10 1 2 7 2 V3 V3 V4 V5 V4 V5 8 4 4 6 6 5 1 1 V6 V7 V6 V7 Finished!

Prim’s algorithm

Basics of Kruskal’s Algorithm Attempts to add edges to A in increasing order of weight (lightest edge first) If the next edge does not induce a cycle among the current set of edges, then it is added to A. If it does, then this edge is passed over, and we consider the next edge in order. As this algorithm runs, the edges of A will induce a forest on the vertices and the trees of this forest are merged together until we have a single tree containing all vertices.

Example: Kruskal’s Algorithm

Kruskal

For Next Class, Friday Dijkstra’s algorithm for finding the shortest path between a source node and a destination node Homework 5 due Tuesday after Spring Break