CS 410/584, Algorithm Design & Analysis, Lecture Notes 4

Similar documents
Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths

Discrete Wiskunde II. Lecture 5: Shortest Paths & Spanning Trees

CS 410/584, Algorithm Design & Analysis: Lecture Notes 3

Contents Lecture 4. Greedy graph algorithms Dijkstra s algorithm Prim s algorithm Kruskal s algorithm Union-find data structure with path compression

1. (12 points) Give a table-driven parse table for the following grammar: 1) X ax 2) X P 3) P DT 4) T P 5) T ε 7) D 1

CS 4407 Algorithms Lecture: Shortest Path Algorithms

Dynamic Programming: Shortest Paths and DFA to Reg Exps

CMPS 6610 Fall 2018 Shortest Paths Carola Wenk

Single Source Shortest Paths

Preliminaries. Graphs. E : set of edges (arcs) (Undirected) Graph : (i, j) = (j, i) (edges) V = {1, 2, 3, 4, 5}, E = {(1, 3), (3, 2), (2, 4)}

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

CS 6301 PROGRAMMING AND DATA STRUCTURE II Dept of CSE/IT UNIT V GRAPHS

Dynamic Programming: Shortest Paths and DFA to Reg Exps

6.889 Lecture 4: Single-Source Shortest Paths

Single Source Shortest Paths

25. Minimum Spanning Trees

25. Minimum Spanning Trees

Design and Analysis of Algorithms

CS781 Lecture 3 January 27, 2011

Question Paper Code :

CMPS 2200 Fall Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk. 10/8/12 CMPS 2200 Intro.

Analysis of Algorithms. Outline. Single Source Shortest Path. Andres Mendez-Vazquez. November 9, Notes. Notes

Ring Sums, Bridges and Fundamental Sets

CSC 1700 Analysis of Algorithms: Warshall s and Floyd s algorithms

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Algorithm Design and Analysis

CSE 332. Data Abstractions

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11

Shortest Path Algorithms

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya

Breadth-First Search of Graphs

Algorithm Design and Analysis

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker

Introduction to Algorithms

Algorithm Design CS 515 Fall 2015 Sample Final Exam Solutions

Formal Languages, Automata and Compilers

Introduction to Algorithms

Greedy. Outline CS141. Stefano Lonardi, UCR 1. Activity selection Fractional knapsack Huffman encoding Later:

Solutions. Prelim 2[Solutions]

Data Structures in Java

Partha Sarathi Mandal

5. Biconnected Components of A Graph

CS 161: Design and Analysis of Algorithms

Algorithm Design and Analysis

Lecture 7: Shortest Paths in Graphs with Negative Arc Lengths. Reading: AM&O Chapter 5

Discrete Optimization 2010 Lecture 3 Maximum Flows

CSE 4502/5717 Big Data Analytics Spring 2018; Homework 1 Solutions

8 Priority Queues. 8 Priority Queues. Prim s Minimum Spanning Tree Algorithm. Dijkstra s Shortest Path Algorithm

CSE 431/531: Analysis of Algorithms. Dynamic Programming. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

Introduction to Algorithms

Path Queries under Distortions: Answering and Containment

Introduction to Algorithms

Algorithms: Lecture 12. Chalmers University of Technology

Slides for CIS 675. Huffman Encoding, 1. Huffman Encoding, 2. Huffman Encoding, 3. Encoding 1. DPV Chapter 5, Part 2. Encoding 2

CMPSCI611: The Matroid Theorem Lecture 5

CS213d Data Structures and Algorithms

Prelim 2[Solutions] Solutions. 1. Short Answer [18 pts]

Algorithm Design Strategies V

Design and Analysis of Algorithms

MA015: Graph Algorithms

Trees. A tree is a graph which is. (a) Connected and. (b) has no cycles (acyclic).

(tree searching technique) (Boolean formulas) satisfying assignment: (X 1, X 2 )

Scheduling with AND/OR Precedence Constraints

Greedy Algorithms and Data Compression. Curs 2018

Lecture 2: MergeSort. CS 341: Algorithms. Thu, Jan 10 th 2019

Geometric Steiner Trees

All-Pairs Shortest Paths

Theory of Computation

Pruning digraphs for reducing catchment zones

Algorithms and Theory of Computation. Lecture 13: Linear Programming (2)

Lecture 11. Single-Source Shortest Paths All-Pairs Shortest Paths

IS 2610: Data Structures

Analysis of Algorithms. Outline 1 Introduction Basic Definitions Ordered Trees. Fibonacci Heaps. Andres Mendez-Vazquez. October 29, Notes.

Breadth First Search, Dijkstra s Algorithm for Shortest Paths

Data Structures and and Algorithm Xiaoqing Zheng

On shredders and vertex connectivity augmentation

A Minimum Spanning Tree for the #2SAT Problem

OpenFst: An Open-Source, Weighted Finite-State Transducer Library and its Applications to Speech and Language. Part I. Theory and Algorithms

4.8 Huffman Codes. These lecture slides are supplied by Mathijs de Weerd

7.5 Bipartite Matching

UNIVERSITY OF PUNE, PUNE BOARD OF STUDIES IN MATHEMATICS SYLLABUS. F.Y.BSc (Computer Science) Paper-I Discrete Mathematics First Term

Data Structures for Disjoint Sets

CS675: Convex and Combinatorial Optimization Fall 2014 Combinatorial Problems as Linear Programs. Instructor: Shaddin Dughmi

More on NP and Reductions

Algorithms Booklet. 1 Graph Searching. 1.1 Breadth First Search

Closure Properties of Regular Languages. Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism

Discrete Optimization Lecture 5. M. Pawan Kumar

B.C.S.Part I Mathematics (Sem.- I & II) Syllabus to be implemented from June 2013 onwards.

Algorithms and Data Structures (COMP 251) Midterm Solutions

Before we show how languages can be proven not regular, first, how would we show a language is regular?

Correctness of Dijkstra s algorithm

CS60007 Algorithm Design and Analysis 2018 Assignment 1

University of Toronto Department of Electrical and Computer Engineering. Final Examination. ECE 345 Algorithms and Data Structures Fall 2016

Chapter 5 Data Structures Algorithm Theory WS 2017/18 Fabian Kuhn

Dynamic Programming. Data Structures and Algorithms Andrei Bulatov

2-INF-237 Vybrané partie z dátových štruktúr 2-INF-237 Selected Topics in Data Structures

Chapter 8 Dynamic Programming

CS599: Convex and Combinatorial Optimization Fall 2013 Lecture 17: Combinatorial Problems as Linear Programs III. Instructor: Shaddin Dughmi

(v,w) disconnected? bridge? articulatiion point? Update MST during insertion and deletion

Transcription:

CS 0/58,, Biconnectivity Let G = (N,E) be a connected A node a N is an articulation point if there are v and w different from a such that every path from 0 9 8 3 5 7 6 David Maier Biconnected Component Maximal subgraph that is still connected after Express in terms of edges 0 9 8 3 5 5 7 3 6 Articulation point must lie in two components David Maier

CS 0/58,, DFS and Articulation Points Tree, back edges in DFS give clue to articulation points If a is an articulation point that splits v and w, then 3 0 5 6 8 7 9 David Maier 3 DFS and Articulation Points Lemma: G = (N,E) is S = (N,T) is Node a is an articulation i point if and only if. a is the root of S and or. a is not the root and a has some child c in S where there is no David Maier

CS 0/58,, Low Numbers For graph G = (N,E), let T = B = For simplicity, assume DFNum[v] = How high (lowest DFNum) can we hop from a node on a back edge? LOW[v] = min({v} {w there is {x,w} in B where David Maier 5 Calculating Low If {x,w} in B and w < v then Also, v is an articulation point if for some child c of v, LOW[c] Calculate LOW during DFS LOW[v] is minimum of.. 3. David Maier 6 3

CS 0/58,, Biconnected Components Algorithm Count Parent[v] BI(v) mark v DFNum[v] Count, increment Count Low[v] DFNum[v] David Maier 7 Algorithm Cont. for each edge {v,w} do if w not marked then if LOW[w] DFNum[v] and v not root then LOW[v] else if PARENT[v] w then LOW[v] Need a check at end if root is an articulation point. David Maier 8

CS 0/58,, 0 9 8 Example 3 5 7 6 David Maier 9 Minimum Cost Spanning Tree G = (N, E) Cost function c gives edge weights A spanning tree is a graph S = ( ) where E E and S is a 3 3 5 6 7 3 6 David Maier 0 5

CS 0/58,, Cost of a spanning tree S = (N,E ) is e E Cost of a Spanning Tree Want minimum cost Lemma: Let S = (N,E ) be a spanning tree for G = (N,E). Then a. for v, v in N b. adding an edge from E-E to S David Maier Spanning Forest A set of trees {(N,E ), (N,E ),..., (N k,e k )} Where N = E i E E j 3 5 3 6 7 3 6 David Maier 6

CS 0/58,, Expanding a Spanning Forest Lemma: Suppose we have a spanning forest of k > trees. Let E = Let e = {v,w} be such that v N, w N. Then there is a spanning tree for G that includes E and has minimal cost among trees that include E. What kind of algorithm is this leading us towards? David Maier 3 Proof of Lemma Suppose not. Let S = (N,E ), E E, have lower cost than any spanning tree Adding e to S causes v w N v w David Maier 7

CS 0/58,, Proof of Lemma S must have an edge e = {v,w } with We know c(e) Let S = S S has no cycles c(e ) S is still a tree David Maier 5 Greedy Strategy Take least cost edge e in E. By last lemma, [Consider an initial spanning forest {({ }, ), ({ }, ),..., ({ }, )} ] David Maier 6 8

CS 0/58,, Iterative Step Let {(N,E ),(N,E ),...,(N k,e k )} be a spanning forest that is Add the lowest cost edge that By the last lemma, the result is David Maier 7 Kruskal s Algorithm KRUSKAL(G(N,E)) S NS {{v },{v },...,{v n }} Q while NS > do {v,w} if Find(v) Find(w) then S S Union( ) David Maier 8 9

CS 0/58,, Example Q c NS {,5} {} {} {3} {} {5} {6} {3,} {,} 3 {,5} 3 {,3} {,6} {,3} 6 {5,6} 7 David Maier 9 Complexity Priority Queue: sort, make a list Union/Find # Union s = # Find s = Can do a little better keep a heap of edges by cost David Maier 0 0

CS 0/58,, Path Problems Directed graphs with labels on edges a b 3 c e d 5 f David Maier Shortest Path Labels could be non-negative integers Use for 3 3 3 5 6 David Maier

CS 0/58,, Connectivity Labels could be Boolean values Use for 3 0 5 0 David Maier 3 Finite Automata Labels could be symbols from an alphabet (as in a finite automaton). Use for a b 3 b a b 5 a David Maier

CS 0/58,, Path Algorithms Can produce generic algorithms, just need definitions for Can take advantage of identities Two kinds of algorithms.. Can do. with David Maier 5 Dijkstra s Algorithm Single-source, shortest path in a digraph v 0 v v 5 v 3 v 9 7 3 v 6 v 7 v 8 v5 S D array of distances David Maier 6 3

CS 0/58,, General Step Add node not in S with minimum D value to S. Update distances to nodes in N-S Is S still correct? S v 0 w suppose not shortest David Maier 7 Full Algorithm G = (N,E) lab(v,w) - label represent with matrix S {v 0 } D[v 0 ] 0 D[v] lab(v 0,v) for rest while S N do choose w S for all v in N-S do D[v] David Maier 8

CS 0/58,, Example 3 3 5 6 S D[] D[] D[3] D[] D[5] {} 0 David Maier 9 Warshall s Algorithm Transitive Closure 3 5 Basic op k v w Consider each k only once v k w David Maier 30 5

CS 0/58,, Algorithm for k = to n do for v = to n do if a[v,k] then for w = to n do if a[k,w] then David Maier 3 Example 3 5 0 0 0 0 0 3 0 0 0 0 0 0 0 5 0 0 David Maier 3 6

CS 0/58,, Floyd s Algorithm All-pairs shortest path v k w for k = to n do for v = to n do if d[v,k] then for w = to n do d[v,w] David Maier 33 Example 3 3 3 d[i,j] 0 0 0 3 0 3 0 David Maier 3 7

CS 0/58,, Example 3 d[i,j] 0 0 0 3 0 3 0 3 d[i,j] 3 David Maier 35 Example 3 3 d[i,j] 0 0 3 0 3 3 6 0 3 d[i,j] 0 3 0 3 3 0 3 3 5 0 David Maier 36 8

CS 0/58,, Example 3 3 d[i,j] 0 3 0 3 3 0 3 3 5 0 3 d[i,j] 3 3 David Maier 37 9