Data Structures and Algorithms I Day 19, 11/3/11 Edge-Weighted Graphs

Slides:



Advertisements
Similar presentations
Single Source Shortest Paths
Advertisements

Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Minimum Spanning Tree 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 Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
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.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
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.
Minimum Spanning Trees Easy. Terms Node Node Edge Edge Cut Cut Cut respects a set of edges Cut respects a set of edges Light Edge Light Edge Minimum Spanning.
Minimum spanning trees (MST) Def: A spanning tree of a graph G is an acyclic subset of edges of G connecting all vertices in G. A sub-forest of G is an.
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
Data Structures and Algorithms I
Graph Search Applications, Minimum Spanning Tree
Lecture ? The Algorithms of Kruskal and Prim
Minimum Spanning Trees
Minimum Spanning Trees
Data Structures and Algorithms I
Shortest Paths and Minimum Spanning Trees
Single-Source Shortest Paths
Shortest Paths C B A E D F Shortest Paths 1
Minimum Spanning Tree Chapter 13.6.
Minimum Spanning Trees
Data Structures and Algorithms I
C.Eng 213 Data Structures Graphs Fall Section 3.
Lecture 12 Algorithm Analysis
CISC 235: Topic 10 Graph Algorithms.
Minimum Spanning Trees
Short paths and spanning trees
Data Structures & Algorithms Graphs
Graph Algorithm.
Minimum-Cost Spanning Tree
Minimum Spanning Tree.
Minimum Spanning Trees
Minimum Spanning Tree Neil Tang 3/25/2010
Connected Components Minimum Spanning Tree
Minimum Spanning Tree.
CSE373: Data Structures & Algorithms Lecture 12: Minimum Spanning Trees Catie Baker Spring 2015.
Shortest-Paths Trees Kun-Mao Chao (趙坤茂)
Minimum-Cost Spanning Tree
Data Structures – LECTURE 13 Minumum spanning trees
Minimum-Cost Spanning Tree
Kruskal’s Minimum Spanning Tree Algorithm
Algorithms and Data Structures Lecture XIII
Autumn 2015 Lecture 10 Minimum Spanning Trees
Lecture 12 Algorithm Analysis
CSE373: Data Structures & Algorithms Lecture 19: Spanning Trees
Minimum Spanning Tree Algorithms
Shortest Paths and Minimum Spanning Trees
Minimum Spanning Tree Neil Tang 4/3/2008
Honors Track: Competitive Programming & Problem Solving Avoiding negative edges Steven Ge.
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
Chapter 24: Single-Source Shortest Paths
Weighted Graphs & Shortest Paths
Autumn 2016 Lecture 10 Minimum Spanning Trees
Minimum spanning trees
Chapter 24: Single-Source Shortest Paths
CSE 417: Algorithms and Computational Complexity
Lecture 12 Algorithm Analysis
Prim’s algorithm for minimum spanning trees
Winter 2019 Lecture 10 Minimum Spanning Trees
CSE 373: Data Structures and Algorithms
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Topological Sorting Minimum Spanning Trees Shortest Path
Minimum-Cost Spanning Tree
Data Structures and Algorithms I
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:

Data Structures and Algorithms I Day 19, 11/3/11 Edge-Weighted Graphs CMP 338 Data Structures and Algorithms I Day 19, 11/3/11 Edge-Weighted Graphs

Homework 11 due: noon 11/4 Implement 2-3 trees directly (Algorithms 3.3.35 pg 452) public class Homework11 extends AbstractOrderedSymbolTable (or) implements OrderedSymbolTable Implement different classes for 2-Nodes and 3-Nodes Preserve 2-3 tree invariants: Keys are ordered in the 2-3 tree All paths from leaves to root are the same length Correctness test: FrequencyCounter on tale.txt

Homework 12 due: 11pm 11/8 Shortest path in a grid (Algorithms 4.4.33 p.g. 689) public class Homework12 public double length(double[][] grid) grid: NxM two-dimensional array of doubles > 0 Nodes: <r, c> where 0<=r<N and 0<=c<M Edges: <<r, c>, <r, c+1>> and <<r,c>, <r+1, c>> weight (<r, c>, <r', c'>): grid(r, c) + grid(r', c') return “length” of shortest path from <0, 0> to <N-1, M-1> Extra credit: also handle edges from <r, c> to <r-1, c> and <r, c-1>

Spanning Tree (Undirected Graph) A tree in an undirected graph: A set of connected edges not containing a cycle A spanning tree or an undirected graph: A tree that connects each vertex of the graph A spanning forest of an undirected graph: Set of spanning trees of the connected components A minimum spanning tree (MST) of a weighted graph The spanning tree with minimum total weight

Prim's MST Algorithm Use priority queue to keep track of the edges mark any node while exists an edge from marked to unmarked pick the shortest such edge add the edge to the MST mark the unmarked vertex Use priority queue to keep track of the edges Optimization: only 1 edge per unmarked node Need to be able to reduce a key in a priority queue Running-time: ||E|| + ||V|| lg ||V||

Kruskal's MST Algorithm while exists an unconsidered edge consider the shortest unconsidered edge if it would not create a cycle add the edge to MST Use priority queue to keep track of the edges Cycle detection: Disjoint Union / Find algorithm Edge will create a cycle iff both end-points in the same set Adding an edge to MST requires union of two sets Running-time: ||E|| lg ||E||

Shortest Path Algorithms Shortest paths in edge-weighted directed graphs Problem ill-formed if any negative cycle is reachable If graph is a DAG Relax nodes in topological order O(||E|| + ||V||) If all edges are non-negative (Dijkstra) Mark and relax nearest unmarked node O(||E||+||V|| lg ||V||) General edge-weighted directed graphs (Bellman-Ford) Repeat up to ||V|| times: Relax nodes changed in previous iteration O(||E|| ||V||)

Relaxation void relax (Node n) for Node m in edgeFrom(n) relax(n, m) void relax (Node n, Node m) If dist(s, n) + w(n, m) < dist(s, m) dist(s, m) = dist(s, n) + w(n, m) parent(m) = n dist is a Map<Node, Double> parent is a Map<Node, Node>

Dijkstra's Shortest Path Algorithm mark the source node while exists an edge from marked to unmarked pick closest unmarked node n to source pick shortest edge from marked to n add edge to Shortest-Path tree mark and relax n Use priority queue to order unmarked nodes Running-time: ||E|| + ||V|| lg ||V||