CS 473: Algorithms. Chandra Chekuri 3228 Siebel Center. Fall University of Illinois, Urbana-Champaign

Similar documents
Depth First Search (DFS)

Depth First Search (DFS)

CSE 101. Algorithm Design and Analysis Miles Jones and Russell Impagliazzo Miles Office 4208 CSE Building

Strongly Connected Components

Graph Representations and Traversal

Design and Analysis of Algorithms

Depth-first search in undirected graphs What parts of the graph are reachable from a given vertex?

Finding Strongly Connected Components

1 Connected components in undirected graphs

Algorithm Design and Analysis

Graph Search. CS/ECE 374: Algorithms & Models of Computation, Fall Lecture 15. October 18, 2018

CS483 Design and Analysis of Algorithms

Lecture 22 Tuesday, April 10

Graph Search. Algorithms & Models of Computation CS/ECE 374, Fall Lecture 15. Thursday, October 19, 2017

Fundamental Graph Algorithms Part Four

Graph Algorithms Using Depth First Search

Strongly Connected Components. Andreas Klappenecker

Strongly connected: A directed graph is strongly connected if every pair of vertices are reachable from each other.

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting

Copyright 2000, Kevin Wayne 1

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

Lecture 3: Graphs and flows

Lecture 10: Strongly Connected Components, Biconnected Graphs

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

3.1 Basic Definitions and Applications

Graphs: Connectivity. Jordi Cortadella and Jordi Petit Department of Computer Science

Graph Algorithms. Imran Rashid. Jan 16, University of Washington

Algorithm Design and Analysis

Graph Algorithms. Andreas Klappenecker. [based on slides by Prof. Welch]

CS781 Lecture 2 January 13, Graph Traversals, Search, and Ordering

Chapter 3. Graphs CLRS Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Copyright 2000, Kevin Wayne 1

Chapter 3. Graphs. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Directed Graphs (II) Hwansoo Han

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

Algorithms and Data Structures

3.1 Basic Definitions and Applications. Chapter 3. Graphs. Undirected Graphs. Some Graph Applications

Fundamental Graph Algorithms Part Three

GNU Make 1. 1 material adapted from GNU Make by Richard Stallman

DFS & STRONGLY CONNECTED COMPONENTS

CSE 417: Algorithms and Computational Complexity. 3.1 Basic Definitions and Applications. Goals. Chapter 3. Winter 2012 Graphs and Graph Algorithms

Depth-First Search Depth-first search (DFS) is another way to traverse the graph.

3.1 Basic Definitions and Applications

CSCE 750, Fall 2002 Notes 6 Page Graph Problems ffl explore all nodes (breadth first and depth first) ffl find the shortest path from a given s

Inf 2B: Graphs II - Applications of DFS

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number:

22.3 Depth First Search

Notes for Recitation 8

Graph Representation

3.4 Testing Bipartiteness

CS 361 Data Structures & Algs Lecture 15. Prof. Tom Hayes University of New Mexico

Question Points Score TOTAL 50

CS240: Programming in C. Lecture 2: Overview

Algorithms: Lecture 10. Chalmers University of Technology

Proof: if not f[u] < d[v], then u still grey while v is being visited. DFS visit(v) will then terminate before DFS visit(u).

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

U.C. Berkeley CS170 : Algorithms, Fall 2013 Midterm 1 Professor: Satish Rao October 10, Midterm 1 Solutions

Lecture 10. Finding strongly connected components

Introduction to Graphs. CS2110, Spring 2011 Cornell University

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 5: SCC/BFS

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department

1. Further Applications of Graph Traversal

Midterm 1 for CS 170

CS 125 Section #6 Graph Traversal and Linear Programs 10/13/14

Algorithms and Theory of Computation. Lecture 3: Graph Algorithms

CS4800: Algorithms & Data Jonathan Ullman

Graphs. Part I: Basic algorithms. Laura Toma Algorithms (csci2200), Bowdoin College

1 Heaps. 1.1 What is a heap? 1.2 Representing a Heap. CS 124 Section #2 Heaps and Graphs 2/5/18

Algorithms (V) Path in Graphs. Guoqiang Li. School of Software, Shanghai Jiao Tong University

CHAPTER 13 GRAPH ALGORITHMS ORD SFO LAX DFW

Announcements. HW3 is graded. Average is 81%

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

Lecture 10 Graph algorithms: testing graph properties

Lecture 16: Directed Graphs

9.5 Equivalence Relations

Plan. CMPSCI 311: Introduction to Algorithms. Recall. Adjacency List Representation. DFS Descriptions. BFS Description

Graph Algorithms. Definition

Graphs. A graph is a data structure consisting of nodes (or vertices) and edges. An edge is a connection between two nodes

Graph Algorithms: Chapters Part 1: Introductory graph concepts

CS Algorithms and Complexity

Algorithm Design and Analysis

CS240: Programming in C

CS261: Problem Set #1

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Basic Graph Theory with Applications to Economics

CS 220: Discrete Structures and their Applications. graphs zybooks chapter 10

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

Total Score /1 /20 /41 /15 /23 Grader

U.C. Berkeley CS170 : Algorithms Midterm 1 Lecturers: Alessandro Chiesa and Satish Rao September 18, Midterm 1

Design and Analysis of Algorithms

Final. Name: TA: Section Time: Course Login: Person on Left: Person on Right: U.C. Berkeley CS170 : Algorithms, Fall 2013

CS 270 Algorithms. Oliver Kullmann. Analysing BFS. Depth-first search. Analysing DFS. Dags and topological sorting.

Algorithms for Minimum Spanning Trees

CISC 320 Introduction to Algorithms Fall Lecture 15 Depth First Search

CSE 101- Winter 18 Discussion Section Week 2

Lecture 20 : Trees DRAFT

These are not polished as solutions, but ought to give a correct idea of solutions that work. Note that most problems have multiple good solutions.

CS 6783 (Applied Algorithms) Lecture 5

Transcription:

CS 473: Algorithms Chandra chekuri@cs.illinois.edu 3228 Siebel Center University of Illinois, Urbana-Champaign Fall 2010

Depth First Search Directed Graphs Searching ted Graphs Strong Connected Components (SCCs) B A C E F D G H efinition Algorithmic Problem directed Find all graph SCCs(also of a given calledirected a digraph) graph. is G = (V, E), where V is a set of vertices or nodes Previous lecture: saw an O(n (n + m)) time algorithm. This lecture: O(n + m) time algorithm. E V V is set of ordered pairs of vertices called edges

Graph of SCCs B A C B, E, F A, C, D E F D G H G H Figure: Graph G Figure: Graph of SCCs G SCC Meta-graph of SCCs Let S 1, S 2,... S k be the SCCs of G. The graph of SCCs is G SCC Vertices are S 1, S 2,... S k There is an edge (S i, S j ) if there is some u S i and v S j such that (u, v) is an edge in G.

Reversal and SCCs Proposition For any graph G, the graph of SCCs of G rev is the same as the reversal of G SCC. Proof. Exercise.

SCCs and DAGs Proposition For any graph G, the graph G SCC has no directed cycle.

SCCs and DAGs Proposition For any graph G, the graph G SCC has no directed cycle. Proof. If G SCC has a cycle S 1, S 2,..., S k then S 1 S 2 S k is an SCC in G. Formal details: exercise.

Part I Directed Acyclic Graphs

Directed Acyclic Graphs Definition A directed graph G is a directed acyclic graph (DAG) if there is no directed cycle in G. 2 3 1 4

Sources and Sinks 2 3 source sink 1 4 Definition A vertex u is a source if it has no in-coming edges. A vertex u is a sink if it has no out-going edges.

Simple DAG Properties Every DAG G has at least one source and at least one sink.

Simple DAG Properties Every DAG G has at least one source and at least one sink. If G is a DAG if and only if G rev is a DAG.

Simple DAG Properties Every DAG G has at least one source and at least one sink. If G is a DAG if and only if G rev is a DAG. G is a DAG if and only each node is in its own strong connected component.

Simple DAG Properties Every DAG G has at least one source and at least one sink. If G is a DAG if and only if G rev is a DAG. G is a DAG if and only each node is in its own strong connected component.

Simple DAG Properties Every DAG G has at least one source and at least one sink. If G is a DAG if and only if G rev is a DAG. G is a DAG if and only each node is in its own strong connected component. Formal proofs: exercise.

Topological Ordering/Sorting 2 3 1 2 3 4 1 4 Figure: Topological Ordering of G Figure: Graph G Definition A topological ordering/sorting of G = (V, E) is an ordering < on V such that if (u, v) E then u < v.

DAGs and Topological Sort Lemma A directed graph G can be topologically ordered iff it is a DAG.

DAGs and Topological Sort Lemma A directed graph G can be topologically ordered iff it is a DAG. Proof. Only if: Suppose G is not a DAG and has a topological ordering <. G has a cycle C = u 1, u 2,..., u k, u 1. Then u 1 < u 2 <... < u k < u 1! A contradiction.

DAGs and Topological Sort Lemma A directed graph G can be topologically ordered iff it is a DAG. Proof. If: Consider the following algorithm: Pick a source u, output it. Remove u and all edges out of u. Repeat until graph is empty. Exercise: prove this gives an ordering. Exercise: show above algorithm can be implemented in O(m + n) time.

Topological Sort: An Example 2 3 Output: 1 4

Topological Sort: An Example 2 3 Output: 1 1 4

Topological Sort: An Example 2 3 Output: 1 2 1 4

Topological Sort: An Example 2 3 Output: 1 2 3 1 4

Topological Sort: An Example 2 3 Output: 1 2 3 4 1 4

Topological Sort: Another Example a b c d e f g h

DAGs and Topological Sort Note: A DAG G may have many different topological sorts. Question: What is a DAG with the most number of distinct topological sorts for a given number n of vertices? Question: What is a DAG with the least number of distinct topological sorts for a given number n of vertices?

DFS to check for Acylicity and Topological Ordering Question Given G, is it a DAG? If it is, generate a topological sort.

DFS to check for Acylicity and Topological Ordering Question Given G, is it a DAG? If it is, generate a topological sort. DFS based algorithm: Compute DFS(G) If there is a back edge then G is not a DAG. Otherwise output nodes in decreasing post-visit order.

DFS to check for Acylicity and Topological Ordering Question Given G, is it a DAG? If it is, generate a topological sort. DFS based algorithm: Compute DFS(G) If there is a back edge then G is not a DAG. Otherwise output nodes in decreasing post-visit order. Correctness relies on the following: Proposition G is a DAG iff there is no back-edge in DFS(G). Proposition If G is a DAG and post(v) > post(u), then (u, v) is not in G.

Example 2 3 1 4

Back edge and Cycles Proposition G has a cycle iff there is a back-edge in DFS(G). Proof. If: (u, v) is a back edge implies there is a cycle C consisting of the path from v to u in DFS search tree and the edge (u, v).

Back edge and Cycles Proposition G has a cycle iff there is a back-edge in DFS(G). Proof. If: (u, v) is a back edge implies there is a cycle C consisting of the path from v to u in DFS search tree and the edge (u, v). Only if: Suppose there is a cycle C = v 1 v 2... v k v 1. Let v i be first node in C visited in DFS. All other nodes in C are descendents of v i since they are reachable from v i. Therefore, (v i 1, v i ) (or (v k, v 1 ) if i = 1) is a back edge.

Proposition If G is a DAG and post(v) > post(u), then (u, v) is not in G. Proof. Assume post(v) > post(u) and (u, v) is an edge in G. We derive a contradiction. One of two cases holds from DFS property. Case 1: [pre(u), post(u)] is contained in [pre(v), post(v)]. Implies that (u, v) is a back edge but a DAG has no back edges! Case 2: [pre(u), post(u)] is disjoint from [pre(v), post(v)]. This cannot happen since v would be explored from u.

DAGs and Partial Orders Definition A partially ordered set is a set S along with a binary relation such that is (i) reflexive (a a for all a V ), (ii) anti-symmetric (a b implies b a) and (iii) transitive (a b and b c implies a c).

DAGs and Partial Orders Definition A partially ordered set is a set S along with a binary relation such that is (i) reflexive (a a for all a V ), (ii) anti-symmetric (a b implies b a) and (iii) transitive (a b and b c implies a c). Example: For numbers in the plane define (x, y) (x, y ) iff x x and y y.

DAGs and Partial Orders Definition A partially ordered set is a set S along with a binary relation such that is (i) reflexive (a a for all a V ), (ii) anti-symmetric (a b implies b a) and (iii) transitive (a b and b c implies a c). Example: For numbers in the plane define (x, y) (x, y ) iff x x and y y. Observation: A finite partially ordered set is equivalent to a DAG. Observation: A topological sort of a DAG corresponds to a complete (or total) ordering of the underlying partial order.

Part II Linear time algorithm for finding all strong connected components of a directed graph

Finding all SCCs of a Directed Graph Problem Given a directed graph G = (V, E), output all its strong connected components.

Finding all SCCs of a Directed Graph Problem Given a directed graph G = (V, E), output all its strong connected components. Straightforward algorithm: For each vertex u V do find SCC(G, u) the strong component containing u as follows: Obtain rch(g, u) using DFS(G, u) Obtain rch(g rev, u) using DFS(G rev, u) Output SCC(G, u) = rch(g, u) rch(g rev, u) Running time: O(n(n + m))

Finding all SCCs of a Directed Graph Problem Given a directed graph G = (V, E), output all its strong connected components. Straightforward algorithm: For each vertex u V do find SCC(G, u) the strong component containing u as follows: Obtain rch(g, u) using DFS(G, u) Obtain rch(g rev, u) using DFS(G rev, u) Output SCC(G, u) = rch(g, u) rch(g rev, u) Running time: O(n(n + m)) Is there an O(n + m) time algorithm?

Structure of a Directed Graph B E A F C D B, E, F A, C, D G H Figure: Graph G G H Figure: Graph of SCCs G SCC Proposition For a directed graph G, its meta-graph G SCC is a DAG.

Linear-time Algorithm for SCCs: Ideas Exploit structure of meta-graph. Algorithm Let u be a vertex in a sink SCC of G SCC Do DFS(u) to compute SCC(u) Remove SCC(u) and repeat Justification DFS(u) only visits vertices (and edges) in SCC(u) DFS(u) takes time proportional to size of SCC(u) Therefore, total time O(n + m)!

Big Challenge(s) How do we find a vertex in the sink SCC of G SCC?

Big Challenge(s) How do we find a vertex in the sink SCC of G SCC? Can we obtain an implicit topological sort of G SCC without computing G SCC?

Big Challenge(s) How do we find a vertex in the sink SCC of G SCC? Can we obtain an implicit topological sort of G SCC without computing G SCC? Answer: DFS(G) gives some information!

Post-visit times of SCCs Definition Given G and a SCC S of G, define post(s) = max u S post(u) where post numbers are with respect to some DFS(G).

An Example [1, 16] B A C [2, 11] B A C [12, 15] E F D [3, 10] E F [6, 7] D [13, 14] [4, 5] G H G H [8, 9] Figure: Graph G Figure: Graph with pre-post times for DFS(A); black edges in tree 11 16 B, E, F A, C, D G H 5 9 Figure: G SCC with post times

G SCC and post-visit times Proposition If S and S are SCCs in G and (S, S ) is an edge in G SCC then post(s) > post(s ).

G SCC and post-visit times Proposition If S and S are SCCs in G and (S, S ) is an edge in G SCC then post(s) > post(s ). Proof. Let u be first vertex in S S that is visited.

G SCC and post-visit times Proposition If S and S are SCCs in G and (S, S ) is an edge in G SCC then post(s) > post(s ). Proof. Let u be first vertex in S S that is visited. If u S then all of S will be explored before DFS(u) completes.

G SCC and post-visit times Proposition If S and S are SCCs in G and (S, S ) is an edge in G SCC then post(s) > post(s ). Proof. Let u be first vertex in S S that is visited. If u S then all of S will be explored before DFS(u) completes. If u S then all of S will be explored before any of S.

G SCC and post-visit times Proposition If S and S are SCCs in G and (S, S ) is an edge in G SCC then post(s) > post(s ). Proof. Let u be first vertex in S S that is visited. If u S then all of S will be explored before DFS(u) completes. If u S then all of S will be explored before any of S.

G SCC and post-visit times Proposition If S and S are SCCs in G and (S, S ) is an edge in G SCC then post(s) > post(s ). Proof. Let u be first vertex in S S that is visited. If u S then all of S will be explored before DFS(u) completes. If u S then all of S will be explored before any of S. A False Statement: If S and S are SCCs in G and (S, S ) is an edge in G SCC then for every u S and u S, post(u) > post(u ).

Topological ordering of G SCC Corollary Ordering SCCs in decreasing order of post(s) gives a topological ordering of G SCC

Topological ordering of G SCC Corollary Ordering SCCs in decreasing order of post(s) gives a topological ordering of G SCC Recall: for a DAG, ordering nodes in decreasing post-visit order gives a topological sort. DFS(G) gives some information on topological ordering of G SCC!

An Example [1, 16] B A C [2, 11] B A C [12, 15] E F D [3, 10] E F [6, 7] D [13, 14] [4, 5] G H G H [8, 9] Figure: Graph G Figure: Graph with pre-post times for DFS(A); black edges in tree 11 16 B, E, F A, C, D G H 5 9 Figure: G SCC with post times

Linear-time Algorithm for SCCs: Ideas Exploit structure of meta-graph. Algorithm Let u be a vertex in a sink SCC of G SCC Do DFS(u) to compute SCC(u) Remove SCC(u) and repeat Justification DFS(u) only visits vertices (and edges) in SCC(u) DFS(u) takes time proportional to size of SCC(u) Therefore, total time O(n + m)!

Big Challenge(s) How do we find a vertex in the sink SCC of G SCC?

Big Challenge(s) How do we find a vertex in the sink SCC of G SCC? Can we obtain an implicit topological sort of G SCC without computing G SCC?

Big Challenge(s) How do we find a vertex in the sink SCC of G SCC? Can we obtain an implicit topological sort of G SCC without computing G SCC? Answer: DFS(G) gives some information!

Finding Sources Proposition The vertex u with the highest post visit time belongs to a source SCC in G SCC

Finding Sources Proposition The vertex u with the highest post visit time belongs to a source SCC in G SCC Proof. post(scc(u)) = post(u) Thus, post(scc(u)) is highest and will be output first in topological ordering of G SCC.

Finding Sinks Proposition The vertex u with highest post visit time in DFS(G rev ) belongs to a sink SCC of G.

Finding Sinks Proposition The vertex u with highest post visit time in DFS(G rev ) belongs to a sink SCC of G. Proof. u belongs to source SCC of G rev Since graph of SCCs of G rev is the reverse of G SCC, SCC(u) is sink SCC of G.

Linear Time Algorithm Do DFS(G rev ) and sort vertices in decreasing post order. Mark all nodes as unvisited for each u in the computed order do if u is not visited then DFS(u) Let S u be the nodes reached by u Output S u as a strong connected component Remove S u from G Analysis Running time is O(n + m). (Exercise)

Linear Time Algorithm: An Example B A C E F D G H Figure: Graph G

Linear Time Algorithm: An Example B A C B A C E F D E F D G H G H Figure: Graph G Figure: G rev

Linear Time Algorithm: An Example B A C [1, 6] [7, 12] B A C [3, 4] E F D [9, 10] E F [8, 11] D [2, 5] G H G [13, 16] H [14, 15] Figure: Graph G Figure: G rev with pre-post times. Red edges not traversed in DFS

Linear Time Algorithm: An Example B A C [1, 6] [7, 12] B A C [3, 4] E F D [9, 10] E F [8, 11] D [2, 5] G H G [13, 16] H [14, 15] Figure: Graph G Order of second DFS: DFS(G) = {G}; Figure: G rev with pre-post times. Red edges not traversed in DFS

Linear Time Algorithm: An Example B A C [1, 6] [7, 12] B A C [3, 4] E F D [9, 10] E F [8, 11] D [2, 5] G H G [13, 16] H [14, 15] Figure: Graph G Figure: G rev with pre-post times. Red edges not traversed in DFS Order of second DFS: DFS(G) = {G}; DFS(H) = {H};

Linear Time Algorithm: An Example B A C [1, 6] [7, 12] B A C [3, 4] E F D [9, 10] E F [8, 11] D [2, 5] G H G [13, 16] H [14, 15] Figure: Graph G Figure: G rev with pre-post times. Red edges not traversed in DFS Order of second DFS: DFS(G) = {G}; DFS(H) = {H}; DFS(B) = {B, E, F };

Linear Time Algorithm: An Example B A C [1, 6] [7, 12] B A C [3, 4] E F D [9, 10] E F [8, 11] D [2, 5] G H G [13, 16] H [14, 15] Figure: Graph G Figure: G rev with pre-post times. Red edges not traversed in DFS Order of second DFS: DFS(G) = {G}; DFS(H) = {H}; DFS(B) = {B, E, F }; DFS(A) = {A, C, D}.

Obtaining the meta-graph from strong connected components Exercise: Given all the strong connected components of a directed graph G = (V, E) show that the meta-graph G SCC can be obtained in O(m + n) time.

Correctness: more details let S 1, S 2,..., S k be strong components in G

Correctness: more details let S 1, S 2,..., S k be strong components in G Strong components of G rev and G are same and meta-graph of G is reverse of meta-graph of G rev.

Correctness: more details let S 1, S 2,..., S k be strong components in G Strong components of G rev and G are same and meta-graph of G is reverse of meta-graph of G rev. consider DFG(G rev ) and let u 1, u 2,..., u k be such that post(u i ) = post(s i ) = max v Si post(v).

Correctness: more details let S 1, S 2,..., S k be strong components in G Strong components of G rev and G are same and meta-graph of G is reverse of meta-graph of G rev. consider DFG(G rev ) and let u 1, u 2,..., u k be such that post(u i ) = post(s i ) = max v Si post(v). Assume without loss of generality that post(u k ) > post(u k 1 )... post(u 1 ) (renumber otherwise). Then S k, S k 1,..., S 1 is a topological sort of meta-graph of G rev and hence S 1, S 2,..., S k is a topological sort of the meta-graph of G.

Correctness: more details let S 1, S 2,..., S k be strong components in G Strong components of G rev and G are same and meta-graph of G is reverse of meta-graph of G rev. consider DFG(G rev ) and let u 1, u 2,..., u k be such that post(u i ) = post(s i ) = max v Si post(v). Assume without loss of generality that post(u k ) > post(u k 1 )... post(u 1 ) (renumber otherwise). Then S k, S k 1,..., S 1 is a topological sort of meta-graph of G rev and hence S 1, S 2,..., S k is a topological sort of the meta-graph of G. u k has highest post number and DFS(u k ) will explore all of S k which is a sink component in G.

Correctness: more details let S 1, S 2,..., S k be strong components in G Strong components of G rev and G are same and meta-graph of G is reverse of meta-graph of G rev. consider DFG(G rev ) and let u 1, u 2,..., u k be such that post(u i ) = post(s i ) = max v Si post(v). Assume without loss of generality that post(u k ) > post(u k 1 )... post(u 1 ) (renumber otherwise). Then S k, S k 1,..., S 1 is a topological sort of meta-graph of G rev and hence S 1, S 2,..., S k is a topological sort of the meta-graph of G. u k has highest post number and DFS(u k ) will explore all of S k which is a sink component in G. After S k is removed u k 1 has highest post number and DFS(u k 1 ) will explore all of S k 1 which is a sink component in remaining graph G S k. Formal proof by induction.

make utility Computational Problems Part III An Application to make

make utility Computational Problems make Utility [Feldman] Unix utility for automatically building large software applications

make utility Computational Problems make Utility [Feldman] Unix utility for automatically building large software applications A makefile specifies

make utility Computational Problems make Utility [Feldman] Unix utility for automatically building large software applications A makefile specifies Object files to be created,

make utility Computational Problems make Utility [Feldman] Unix utility for automatically building large software applications A makefile specifies Object files to be created, Source/object files to be used in creation, and

make utility Computational Problems make Utility [Feldman] Unix utility for automatically building large software applications A makefile specifies Object files to be created, Source/object files to be used in creation, and How to create them

make utility Computational Problems An Example makefile project: main.o utils.o command.o cc -o project main.o utils.o command.o main.o: main.c defs.h cc -c main.c utils.o: utils.c defs.h command.h cc -c utils.c command.o: command.c defs.h command.h cc -c command.c

make utility Computational Problems makefile as a Digraph main.c utils.c main.o defs.h utils.o project command.h command.c command.o

make utility Computational Problems Computational Problems for make Is the makefile reasonable?

make utility Computational Problems Computational Problems for make Is the makefile reasonable? If it is reasonable, in what order should the object files be created?

make utility Computational Problems Computational Problems for make Is the makefile reasonable? If it is reasonable, in what order should the object files be created? If it is not reasonable, provide helpful debugging information.

make utility Computational Problems Computational Problems for make Is the makefile reasonable? If it is reasonable, in what order should the object files be created? If it is not reasonable, provide helpful debugging information. If some file is modified, find the fewest compilations needed to make application consistent.

make utility Computational Problems Algorithms for make Is the makefile reasonable? Is G a DAG?

make utility Computational Problems Algorithms for make Is the makefile reasonable? Is G a DAG? If it is reasonable, in what order should the object files be created? Find a topological sort of a DAG.

make utility Computational Problems Algorithms for make Is the makefile reasonable? Is G a DAG? If it is reasonable, in what order should the object files be created? Find a topological sort of a DAG. If it is not reasonable, provide helpful debugging information. Output a cycle. More generally, output all strong connected components.

make utility Computational Problems Algorithms for make Is the makefile reasonable? Is G a DAG? If it is reasonable, in what order should the object files be created? Find a topological sort of a DAG. If it is not reasonable, provide helpful debugging information. Output a cycle. More generally, output all strong connected components. If some file is modified, find the fewest compilations needed to make application consistent.

make utility Computational Problems Algorithms for make Is the makefile reasonable? Is G a DAG? If it is reasonable, in what order should the object files be created? Find a topological sort of a DAG. If it is not reasonable, provide helpful debugging information. Output a cycle. More generally, output all strong connected components. If some file is modified, find the fewest compilations needed to make application consistent. Find all vertices reachable (using DFS/BFS) from modified files in directed graph, and recompile them in proper order. Verify that one can find the files to recompile and the ordering in linear time.

make utility Computational Problems Takeaway Points Given a directed graph G, its SCCs and the associated acyclic meta-graph G SCC give a structural decomposition of G that should be kept in mind. There is a DFS based linear time algorithm to compute all the SCCs and the meta-graph. Properties of DFS crucial for the algorithm. DAGs arise in many application and topological sort is a key property in algorithm design. Linear time algorithms to compute a topological sort (there can be many possible orderings so not unique).