1 Finding Dominators in Flowgraphs Linear-Time Algorithm 1 and Experimental Study 2 Loukas Georgiadis 1 joint work with Robert E. Tarjan 2 joint work with.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Graph Algorithms
Advertisements

What is a graph ? G=(V,E) V = a set of vertices E = a set of edges edge = unordered pair of vertices
Graphs - II Algorithms G. Miller V. Adamchik CS Spring 2014 Carnegie Mellon University.
Advanced Topics in Algorithms and Data Structures
Theory of Computing Lecture 6 MAS 714 Hartmut Klauck.
More Graphs COL 106 Slides from Naveen. Some Terminology for Graph Search A vertex is white if it is undiscovered A vertex is gray if it has been discovered.
Discrete Structures Lecture 13: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
1 Dominators in a Flowgraph Dominators in a Flowgraph Flowgraph: G = (V, E, r); each v in V is reachable from r v dominates w if every path from r to w.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
A Randomized Linear-Time Algorithm to Find Minimum Spaning Trees 黃則翰 R 蘇承祖 R 張紘睿 R 許智程 D 戴于晉 R David R. Karger.
Applications of graph traversals
Binary Trees, Binary Search Trees COMP171 Fall 2006.
Jeffrey D. Ullman Stanford University Flow Graph Theory.
Data Structures & Algorithms Graph Search Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Advanced Compilers CMPSCI 710 Spring 2003 Lecture 2 Emery Berger University of.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
DAST 2005 Tirgul 11 (and more) sample questions. DAST 2005 Q.Let G = (V,E) be an undirected, connected graph with an edge weight function w : E→R. Let.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 10 Instructor: Paul Beame.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Mergeable Trees1 Mergeable Trees Mergeable Trees Robert E. Tarjan Princeton University and HP Labs Joint work with Loukas Georgiadis, Haim Kaplan, Nira.
The Complexity of Algorithms and the Lower Bounds of Problems
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Trees.
Elementary graph algorithms Chapter 22
Tirgul 7 Review of graphs Graph algorithms: – BFS (next tirgul) – DFS – Properties of DFS – Topological sort.
Backtracking.
Trees and Tree Traversals Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Graph Algorithms Using Depth First Search Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
Directed graphs Definition. A directed graph (or digraph) is a pair (V, E), where V is a finite non-empty set of vertices, and E is a set of ordered pairs.
A Fast Algorithm To Determine Minimality of Strongly Connected Digraphs Under the direction of Dr. Robinson By Jianping Zhu.
Fixed Parameter Complexity Algorithms and Networks.
ساختمانهای گسسته دانشگاه صنعتی شاهرود – اردیبهشت 1392.
Chapter 2 Graph Algorithms.
CSC 213 – Large Scale Programming. Today’s Goals  Make Britney sad through my color choices  Revisit issue of graph terminology and usage  Subgraphs,
Graphs.
Preview  Graph  Tree Binary Tree Binary Search Tree Binary Search Tree Property Binary Search Tree functions  In-order walk  Pre-order walk  Post-order.
Discrete Structures Trees (Ch. 11)
Chap 8 Trees Def 1: A tree is a connected,undirected, graph with no simple circuits. Ex1. Theorem1: An undirected graph is a tree if and only if there.
A new linear algorithm for checking a graph for 3-edge-connectivity Feng Sun Advisor: Dr. Robert W. Robinson Committee: Dr. E. Rodney Canfield Dr. Eileen.
Jan Topological Order and SCC Edge classification Topological order Recognition of strongly connected components.
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Graphs A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Trees, Binary Search Trees, Balanced Trees, Graphs Graph Fundamentals Telerik Algo Academy
Depth-First Search Lecture 21: Graph Traversals
Introduction to Graph Theory Lecture 17: Graph Searching Algorithms.
24 January Trees CSE 2011 Winter Trees Linear access time of linked lists is prohibitive  Does there exist any simple data structure for.
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 5.
 2004 SDU 1 Lecture5-Strongly Connected Components.
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.
Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.
Chapter 05 Introduction to Graph And Search Algorithms.
CSE 421 Algorithms Richard Anderson Autumn 2015 Lecture 5.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
5. Biconnected Components of A Graph If one city’s airport is closed by bad weather, can you still fly between any other pair of cities? If one computer.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
CSC 213 – Large Scale Programming Lecture 31: Graph Traversals.
CSC317 1 At the same time: Breadth-first search tree: If node v is discovered after u then edge uv is added to the tree. We say that u is a predecessor.
Breadth-First Search (BFS)
Graph Algorithms BFS, DFS, Dijkstra’s.
12. Graphs and Trees 2 Summary
Binary Trees, Binary Search Trees
Graph Algorithms Using Depth First Search
Minimum Spanning Tree Verification
Analysis of Algorithms
Finding Dominators in Flowgraphs
Binary Trees, Binary Search Trees
Binary Trees, Binary Search Trees
Presentation transcript:

1 Finding Dominators in Flowgraphs Linear-Time Algorithm 1 and Experimental Study 2 Loukas Georgiadis 1 joint work with Robert E. Tarjan 2 joint work with Renato F. Werneck, Robert E. Tarjan, Spyridon Triantafyllis and David I. August

2 Dominators in a Flowgraph Dominators in a Flowgraph Flowgraph: G = (V, E, r); each v in V is reachable from r v dominates w if every path from r to w includes v w v r

3 Dominators in a Flowgraph Dominators in a Flowgraph Flowgraph: G = (V, E, r); each v in V is reachable from r v dominates w if every path from r to w includes v Set of dominators: Dom(w) = { v | v dominates w } Trivial dominators:  w  r, w, r  Dom(w) Immediate dominator: idom(w)  Dom(w) – w and dominated by every v in Dom(w) – w

4 Dominators in a Flowgraph Dominators in a Flowgraph Flowgraph: G = (V, E, r); each v in V is reachable from r v dominates w if every path from r to w includes v Set of dominators: Dom(w) = { v | v dominates w } Trivial dominators:  w  r, w, r  Dom(w) Immediate dominator: idom(w)  Dom(w) – w and dominated by every v in Dom(w) – w Goal: Find idom(v) for each v in V (immediate dominator tree) Applications: Program optimization, code generation, circuit testing

Lengauer and Tarjan; O(m·  (m,n)) time Alstrup, Harel, Lauridsen and Thorup; O(n+m) time for RAM Buchsbaum, Kaplan, Rogers and Westbrook; claimed O(n+m) for Pointer Machine. (Corrected in 2004 to work in linear time for RAM.) 2004 G. and Tarjan We showed that the Buchsbaum et al. algorithm runs in O(m·  (m,n)) time. Based on Buchsbaum et al. we gave a linear-time algorithm for Pointer Machine, simpler than Alstrup et al. (no complicated data structures). History History

6 The Lengauer-Tarjan Algorithm The Lengauer-Tarjan Algorithm Depth-First Search  DFS Tree D We refer to the vertices by their DFS numbers: v < w : v was visited by DFS before w r

7 The Lengauer-Tarjan Algorithm: Semidominators The Lengauer-Tarjan Algorithm: Semidominators Depth-First Search  DFS Tree D We refer to the vertices by their DFS numbers: v < w : v was visited by DFS before w Semidominator path (SDOM-path): P = (v 0 = v, v 1, v 2, …, v k = w) such that v i >w, for 1  i  k-1 r

8 The Lengauer-Tarjan Algorithm: Semidominators The Lengauer-Tarjan Algorithm: Semidominators Depth-First Search  DFS Tree D We refer to the vertices by their DFS numbers: v < w : v was visited by DFS before w Semidominator path (SDOM-path): P = (v 0 = v, v 1, v 2, …, v k = w) such that v i >w, for 1  i  k-1 Semidominator: sdom(w) = min { v |  SDOM-path from v to w } r

9 Overview 1.Carry out a DFS. 2.Process the vertices in reverse preorder. For vertexw, compute sdom(w). 3.Implicitly define idom(w). 4.Explicitly define idom(w) by a preorder pass. The Lengauer-Tarjan Algorithm

10 Data Structure: Maintain forest F and supports the operations: link(v, w): Add the edge (v,w) to F. eval(v): Let r = root of the tree that contains v in F. If v = r then return v. Otherwise return any vertex with minimum sdom among the vertices u that are proper descendants of r and ancestors of v. Initially every vertex in V is a root in F. The Lengauer-Tarjan Algorithm:Evaluate minima on tree paths The Lengauer-Tarjan Algorithm: Evaluate minima on tree paths

11 Data Structure: Maintain forest F and supports the operations: link(v, w): Add the edge (v,w) to F. eval(v): Let r = root of the tree that contains v in F. If v = r then return v. Otherwise return any vertex with minimum sdom among the vertices u that are proper descendants of r and ancestors of v. Initially every vertex in V is a root in F. Simple version: n links, m evals in O(mlogn). Sophisticated version: n links, m evals in O(mα(m,n)). The Lengauer-Tarjan Algorithm:Evaluate minima on tree paths The Lengauer-Tarjan Algorithm: Evaluate minima on tree paths

12 The Linear-Time Algorithm The Linear-Time Algorithm Partition D into trivial and nontrivial microtrees. [Dixon and Tarjan ‘97] Nontrivial microtree: Maximal subtree of D of size  g that contains at least one leaf of D. Trivial microtree: Single internal vertex of D

13 The Linear-Time Algorithm The Linear-Time Algorithm Partition D into trivial and nontrivial microtrees. [Dixon and Tarjan ‘97] Nontrivial microtree: Maximal subtree of D of size  g that contains at least one leaf of D. Trivial microtree: Single internal vertex of D trivial microtree nontrivial microtree g = 3

14 The Linear-Time Algorithm The Linear-Time Algorithm Partition D into trivial and nontrivial microtrees. [Dixon and Tarjan ‘97] Nontrivial microtree: Maximal subtree of D of size  g that contains at least one leaf of D. Trivial microtree: Single internal vertex of D. Core C: Tree D – nontrivial microtrees; has  n/g leaves

15 The Linear-Time Algorithm The Linear-Time Algorithm Partition D into trivial and nontrivial microtrees. [Dixon and Tarjan ‘97] Nontrivial microtree: Maximal subtree of D of size  g that contains at least one leaf of D. Trivial microtree: Single internal vertex of D. Core C: Tree D – nontrivial microtrees; has  n/g leaves. Line: Path (v 1 =s, v 2, …, v k =t) in C such that outdegree C (v i )= 1, 1  i  k- 1, and outdegree C (v k ) = 0 or >

16 The Linear-Time Algorithm The Linear-Time Algorithm Partition D into trivial and nontrivial microtrees. [Dixon and Tarjan ‘97] Nontrivial microtree: Maximal subtree of D of size  g that contains at least one leaf of D. Trivial microtree: Single internal vertex of D. Core C: Tree D – nontrivial microtrees; has  n/g leaves. Line: Path (v 1 =s, v 2, …, v k =t) in C such that outdegree C (v i )= 1, 1  i  k- 1, and outdegree C (v k ) = 0 or > line

17 The Linear-Time Algorithm The Linear-Time Algorithm Partition D into trivial and nontrivial microtrees. [Dixon and Tarjan ‘97] Nontrivial microtree: Maximal subtree of D of size  g that contains at least one leaf of D. Trivial microtree: Single internal vertex of D. Core C: Tree D – nontrivial microtrees; has  n/g leaves. Line: Path (v 1 =s, v 2, …, v k =t) in C such that outdegree C (v i )= 1, 1  i  k- 1, and outdegree C (v k ) = 0 or > 1. There are L  2 n/g lines. Contract each line into a single vertex  tree C’ with L nodes. {1, 2, 3} {4, 7, 8}{15, 17}

18 The Linear-Time Algorithm The Linear-Time Algorithm Extend the definition of semidominators for the vertices of the nontrivial microtrees [Buchsbaum et al.] : Pushed external dominator path (PXDOM-path): P = (v 0 = v, v 1, v 2, …, v k = w) such that v i  root of microtree of w, for 1  i  k- 1. Pushed external dominator: pxdom(w) = min { v |  PXDOM-path from v to w } pxdom(w) w sdom(w)

19 The Linear-Time Algorithm The Linear-Time Algorithm Extend the definition of semidominators for the vertices of the nontrivial microtrees [Buchsbaum et al.] : Pushed external dominator path (PXDOM-path): P = (v 0 = v, v 1, v 2, …, v k = w) such that v i  root of microtree of w, for 1  i  k- 1. Pushed external dominator: pxdom(w) = min { v |  PXDOM-path from v to w } For any vertex w of the core C pxdom(w) = sdom(w) pxdom(w) w sdom(w)

20 Overview 1.Compute internal dominators in each nontrivial microtree. The Linear-Time Algorithm The Linear-Time Algorithm

21 Overview 1.Compute internal dominators in each nontrivial microtree. 2.Compute pxdoms in each nontrivial microtree t by link and eval on C’ and Nearest Common Ancestor (NCA) queries on a tree built by the sdom values of the line that contains the parent of the root of t. The Linear-Time Algorithm The Linear-Time Algorithm

22 Overview 1.Compute internal dominators in each nontrivial microtree. 2.Compute pxdoms in each nontrivial microtree t by link and eval on C’ and Nearest Common Ancestor (NCA) queries on a tree built by the sdom values of the line that contains the parent of the root of t. 3.Compute sdoms in each line l by a top-down pass using link and eval on C’ and contracting connected components in l. The Linear-Time Algorithm The Linear-Time Algorithm

23 Overview 1.Compute internal dominators in each nontrivial microtree. 2.Compute pxdoms in each nontrivial microtree t by link and eval on C’ and Nearest Common Ancestor (NCA) queries on a tree built by the sdom values of the line that contains the parent of the root of t. 3.Compute sdoms in each line l by a top-down pass using link and eval on C’ and contracting connected components in l. Remarks: link and eval run in linear-time on C’. Buchsbam et al. claimed that link and eval run in linear time on C but the claim is false. The Linear-Time Algorithm The Linear-Time Algorithm

24 The Iterative Algorithm: Set-based The Iterative Algorithm: Set-based Dominators can be computed by solving iteratively the set of equations [Allen and Cocke, 1972] Dom(v) = (  u  pred(v) Dom(u) )  {v}, v  r Initialization Dom(r) = {r} Dom(v) = , v  r In the intersection we consider only the nonempty Dom(u).

25 The Iterative Algorithm: Set-based The Iterative Algorithm: Set-based Dominators can be computed by solving iteratively the set of equations [Allen and Cocke, 1972] Dom(v) = (  u  pred(v) Dom(u) )  {v}, v  r Initialization Dom(r) = {r} Dom(v) = , v  r In the intersection we consider only the nonempty Dom(u). Each Dom(v) set can be represented by an n-bit vector. Intersection  bit-wise AND. Requires n 2 space. Very slow in practice.

26 The Iterative Algorithm: Tree-based The Iterative Algorithm: Tree-based Efficient implementation [Cooper, Harvey and Kennedy 2000] dfs(r) T  {r} changed  true while ( changed ) do changed  false for all v in V – r in reverse postorder do x  nca(pred(v)) if x  parent(v) then parent(v)  x changed  true end done

27 The Iterative Algorithm The Iterative Algorithm Running Time Each pair wise intersection takes O(n) time. The number of iterations is  d + 3. [Kam and Ullman ’76] d = max #back-edges in any cycle-free path of G = O(n) Running time = O(mn 2 ) This bound is tight, but very pessimistic in practice.

28 The Iterative Algorithm: Generic Tree-based The Iterative Algorithm: Generic Tree-based T  T 0 /* a spanning (sub)tree of G */ changed  true while ( changed ) do changed  false for all v in V – r in order  do x  nca(pred(v)) if x  parent(v) then parent(v)  x changed  true end done

29 The Iterative Algorithm: Generic Tree-based The Iterative Algorithm: Generic Tree-based T  T 0 /* a spanning (sub)tree of G */ changed  true while ( changed ) do changed  false for all v in V – r in order  do x  nca(pred(v)) if x  parent(v) then parent(v)  x changed  true end done Good choices (in practice): T 0 = a Bread-First Search (BFS) tree  = BFS order

30 A Hybrid Algorithm A Hybrid Algorithm Lemma: For any vertex w  r, idom(w) = NCA( I, parent(w), sdom(w) ). I = (immediate) dominator tree parent(w) = parent of w in the DFS tree D

31 A Hybrid Algorithm A Hybrid Algorithm Lemma: For any vertex w  r, idom(w) = NCA( I, parent(w), sdom(w) ). I = (immediate) dominator tree parent(w) = parent of w in the DFS tree D SEMI-NCA: 1.Compute sdoms as in simple version of LT. 2.Construct I incrementally applying Lemma. (NCA calculations implemented naïvely)

32 Experimental Results Experimental Results Algorithms SLT: simple version of Lengauer-Tarjan LT: almost-linear-time version of Lengauer-Tarjan IDFS: DFS tree-based iterative IBFS: BFS tree-based iterative SNCA: SEMI-NCA

33 Inputs Control-flow graphs from SPARC ’95 generated by the SUIF compiler (Stanford). > 4900 graphs, avg #vertices ~ 40, #edges ~ 55 max #vertices ~ 2100, #edges ~ 3200 Control-flow graphs from SPARC’ 00 generated by the IMPACT compiler (UIUC). > 2000 graphs, avg #vertices ~ 25, #edges ~ 70 max #vertices~ 580, #edges~ 3100 VLSI circuits from ISCAS’89 suite. 50 graphs, avg #vertices ~ 3200, #edges ~ 5000 max #vertices ~ 24000, #edges ~ Experimental Results Experimental Results

34 IDFS IBFS LT SLT SNCA mean dev mean dev mean dev mean dev mean dev CIRCUITS SUIF-INT IMPACT IMPACTP Experimental Results Experimental Results Times relative to BFS: geometric mean and geometric standard deviation

35 iterations comparisons per vertex SDP(%) IDFS IBFS IDFS IBFS LT SLT SNCA CIRCUITS IMPACT IMPACTP SUIF-INT Experimental Results Experimental Results SDP = percentage of vertices v that have parent(v) = sdom(v)

36 Experimental Results