Short paths and spanning trees

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

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:
Minimum Spanning Tree Algorithms
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: Greedy Algorithms The Design and Analysis of Algorithms.
Minimum-Cost Spanning Tree weighted connected undirected graph spanning tree cost of spanning tree is sum of edge costs find spanning tree that has minimum.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
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.
Design and Analysis of Algorithms Minimum Spanning trees
Spanning Trees. Spanning trees Suppose you have a connected undirected graph –Connected: every node is reachable from every other node –Undirected: edges.
1 Minimum Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting.
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.
1 Minimum Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting.
Dijkstra's algorithm.
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
Graphs CS 400/600 – Data Structures. Graphs2 Graphs  Used to represent all kinds of problems Networks and routing State diagrams Flow and capacity.
CS 146: Data Structures and Algorithms July 21 Class Meeting
Graph (II) Shortest path, Minimum spanning tree GGuy
Minimum Spanning Trees
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
COSC 2007 Data Structures II Chapter 14 Graphs III.
Spanning Trees CSIT 402 Data Structures II 1. 2 Two Algorithms Prim: (build tree incrementally) – Pick lower cost edge connected to known (incomplete)
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Minimum Spanning Trees CS 146 Prof. Sin-Min Lee Regina Wang.
1 Prim’s algorithm. 2 Minimum Spanning Tree Given a weighted undirected graph G, find a tree T that spans all the vertices of G and minimizes the sum.
Main Index Contents 11 Main Index Contents Graph Categories Graph Categories Example of Digraph Example of Digraph Connectedness of Digraph Connectedness.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Graph Search Applications, Minimum Spanning Tree
Minimum Spanning Trees
Graphs Representation, BFS, DFS
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
Minimum Spanning Tree Chapter 13.6.
Minimum Spanning Trees
Minimum Spanning Trees and Shortest Paths
CISC 235: Topic 10 Graph Algorithms.
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
The Greedy Approach Winter-2004 Young CS 331 D&A of Algo. Greedy.
Data Structures & Algorithms Graphs
Graph Algorithm.
Minimum-Cost Spanning Tree
Minimum Spanning Tree.
Minimum Spanning Trees
Graph Algorithm.
Minimum Spanning Tree.
Spanning Trees.
Minimum-Cost Spanning Tree
Outline This topic covers Prim’s algorithm:
Minimum-Cost Spanning Tree
Chapter 11 Graphs.
Minimum Spanning Tree Algorithms
Minimum Spanning Trees
Minimum Spanning Tree.
Fundamental Structures of Computer Science II
Chapter 16 1 – Graphs Graph Categories Strong Components
CSE 417: Algorithms and Computational Complexity
The Greedy Approach Young CS 530 Adv. Algo. Greedy.
Spanning Trees Lecture 20 CS2110 – Spring 2015.
Prim’s algorithm for minimum spanning trees
Spanning Trees, greedy algorithms
Minimum-Cost Spanning Tree
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 .
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Short paths and spanning trees Graph minimizations Short paths and spanning trees

Outline Shortest-Path Dijkstra Minimum-Path Algorithm Minimum Spanning Tree Prim’s algorithm Kruskal’s algorithm

Graph-Minimization Algorithms Shortest-Path Algorithm Dijkstra’s Minimum-Path Algorithm Minimum-Spanning Tree Algorithms

Shortest-Path algorithm Find a shortest path (minimum number of edges) from a given vertex vs to every other vertex in a directed graph The shortest-path algorithm includes a queue that indirectly stores the vertices, using the corresponding vInfo index. Each iterative step removes a vertex from the queue and searches its adjacency set to locate all of the unvisited neighbors and add them to the queue.

Shortest-Path Example Example: Find the shortest path from F to C. Book 987-988 Note shortP1-3

Shortest-Path algorithm Implementation Performance Similar to BFS search, O(|V|+|E|) Note shortP1-3

Dijkstra Minimum-Path Algorithm Find the minimum weight (minimum sum of edge weight) from a given vertex to every other vertex in a weighted directed graph Use a minimum priority queue to store the vertices, using minInfo class, which contains a vInfo index and the pathWeight value At each iterative step, the priority queque identifies a new vertex whose pathWeight value is the minimum path weight from the starting vertex

Dijkstra Minimum-Path Algorithm From A to D Example priority queue minInfo( A ,0)

Dijkstra Minimum-Path Algorithm The Dijkastra algorithm is a greedy algorithm at each step, make the best choice available. Usually, greedy algorithms produce locally optimum results, but not globally optimal Dijkstra algorithm produces a globally optimum result Implementation Running-Time Analysis O(|V|+|E|log|E|)

Minimum Spanning Tree Algorithms Minimum Spanning Tree (For Undirected Graph) Tree: a connected graph with no cycles. Spanning Tree: a tree which contains all vertices in G. Note: Connected graph with n vertices and exactly n – 1 edges is Spanning Tree. Minimum Spanning Tree: a spanning Tree with minimum total weight

Minimum Spanning Tree Example

Prim’s Algorithm Basic idea: Start from vertex u and let T  Ø (T will contain all edges in the S.T.); the next edge to be included in T is the minimum cost edge(u, v), s.t. u is currently in the tree T and v is not in T.

Prim’s Algorithm example

Implementation of Prim’s algorithm: Using a priority queque of miniInfo objects to store information Color: White not in tree, Black in tree Data Value: the weight of the minimum edge that would connect the vertex to an existing vertex in tree parent Each iterative steps similar to Dijkstra algorithm

Prim’s Minimum Spanning-Tree Algorithm example: B C D 2 8 12 5 7 (a) Book: 1001-1002, step 1-step 4

Prim’s Minimum Spanning Tree Algorithm Implementation Running-Time Analysis O(|V|+|E|log|E|)

(1,4) 30 × reject create cycle (3,5) 35 √ Kruskal’s Algorithm Basic idea: Don’t care if T is a tree or not in the intermediate stage, as long as the including of a new edge will not create a cycle, we include the minimum cost edge Example: Step 1: Sort all of edges (1,2) 10 √ (3,6) 15 √ (4,6) 20 √ (2,6) 25 √ (1,4) 30 × reject create cycle (3,5) 35 √ 1 2 3 5 4 6 10 50 35 40 55 15 45 25 30 20

Step 2: T 1 2 3 6 4 1 2 3 6 4 5

How to check: adding an edge will create a cycle or not? If Maintain a set for each group (initially each node represents a set) Ex: set1 set2 set3  new edge from different groups  no cycle created Data structure to store sets so that: The group number can be easily found, and Two sets can be easily merged 1 2 3 6 4 5 2 6

Kruskal’s algorithm While (T contains fewer than n-1 edges) and (E   ) do Begin Choose an edge (v,w) from E of lowest cost; Delete (v,w) from E; If (v,w) does not create a cycle in T then add (v,w) to T else discard (v,w); End; Time complexity: O(|V|+|E|log|E|)

§- Dijkstra's algorithm Summary Slide 1 §- Dijkstra's algorithm - if weights, uses a priority queue to determine a path from a starting to an ending vertex, of minimum weight - This idea can be extended to Prim's algorithm, which computes the minimum spanning tree in an undirected, connected graph. 21

§- Minimum Spanning Tree algorithm Summary Slide 2 §- Minimum Spanning Tree algorithm - Prim’s algorithm - Kruskal’s Algorithm 22