CSC 213 – Large Scale Programming. Today’s Goals  Examine new properties of DirectedGraph s  What reaching & reachable mean for a Graph  How humans.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

© 2004 Goodrich, Tamassia Directed Graphs1 JFK BOS MIA ORD LAX DFW SFO.
Directed Graphs Directed Graphs Shortest Path 4/10/ :45 AM BOS
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Graphs – Depth First Search ORD DFW SFO LAX
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
1 The Graph Abstract Data Type CS 5050 Chapter 6.
Connected Components, Directed Graphs, Topological Sort COMP171.
Graphs. Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
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.
Lecture 16 CSE 331 Oct 9, Announcements Hand in your HW4 Solutions to HW4 next week Remember next week I will not be here so.
© 2004 Goodrich, Tamassia Directed Graphs1 JFK BOS MIA ORD LAX DFW SFO.
An almost linear fully dynamic reachability algorithm.
1 Directed Graphs CSC401 – Analysis of Algorithms Lecture Notes 15 Directed Graphs Objectives: Introduce directed graphs and weighted graphs Present algorithms.
TTIT33 Alorithms and Optimization – DALG Lecture 4 Graphs HT TTIT33 Algorithms and optimization Algorithms Lecture 4 Graphs.
Connected Components, Directed Graphs, Topological Sort Lecture 25 COMP171 Fall 2006.
CS344: Lecture 16 S. Muthu Muthukrishnan. Graph Navigation BFS: DFS: DFS numbering by start time or finish time. –tree, back, forward and cross edges.
Directed Graphs1 JFK BOS MIA ORD LAX DFW SFO. Directed Graphs2 Outline and Reading (§6.4) Reachability (§6.4.1) Directed DFS Strong connectivity Transitive.
Connected Components, Directed graphs, Topological sort COMP171 Fall 2005.
Liam Roditty Reachability in Directed Graphs. Connectivity in undirected graphs Given two vertices decide whether they are in the same component. Reachability.
CSC311: Data Structures 1 Chapter 13: Graphs I Objectives: Graph ADT: Operations Graph Implementation: Data structures Graph Traversals: DFS and BFS Directed.
CSC 2300 Data Structures & Algorithms March 30, 2007 Chapter 9. Graph Algorithms.
CS2420: Lecture 36 Vladimir Kulyukin Computer Science Department Utah State University.
Lecture 11 CSE 331 Sep 25, Homeworks Please hand in your HW 2 now HW 3 and graded HW 1 at the end of class.
Review of Graphs A graph is composed of edges E and vertices V that link the nodes together. A graph G is often denoted G=(V,E) where V is the set of vertices.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
MA/CSSE 473 Day 12 Insertion Sort quick review DFS, BFS Topological Sort.
CSC 331: Algorithm Analysis Decompositions of Graphs.
Chapter 2 Graph Algorithms.
Fundamentals, Terminology, Traversal, Algorithms Graph Algorithms Telerik Algo Academy
Introduction to Graphs. Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected.
MA/CSSE 473 Day 15 BFS Topological Sort Combinatorial Object Generation Intro.
Week 11 - Monday.  What did we talk about last time?  Binomial theorem and Pascal's triangle  Conditional probability  Bayes’ theorem.
Lecture 7 All-Pairs Shortest Paths. All-Pairs Shortest Paths.
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.
© 2004 Goodrich, Tamasia Recall: Digraphs A digraph is a graph whose edges are all directed Short for “directed graph” Applications one-way streets flights.
Chapter 10 Graph Theory Eulerian Cycle and the property of graph theory 10.3 The important property of graph theory and its representation 10.4.
CSC 213 – Large Scale Programming. Today’s Goals  Discuss what is meant by weighted graphs  Where weights placed within Graph  How to use Graph ’s.
CSC 213 – Large Scale Programming. Graphs  Mathematically, graph is pair (V, E) where  V is collection of nodes, called vertices  Two nodes can be.
CSC2100B Tutorial 10 Graph Jianye Hao.
CSCI2100 Data Structures Tutorial 12
Graph Revisited Fei Chen CSCI2100B Data Structures Tutorial 12 1.
1 Digraphs Reachability Connectivity Transitive Closure Floyd-Warshall Algorithm JFK BOS MIA ORD LAX DFW SFO v 2 v 1 v 3 v 4 v 5 v 6 v 7.
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Paths and circuits.
Directed Graphs1 JFK BOS MIA ORD LAX DFW SFO. Directed Graphs2 Outline and Reading (§12.4) Reachability (§12.4.1) Directed DFS Strong connectivity Transitive.
Week 11 - Wednesday.  What did we talk about last time?  Exam 2  And before that:  Graph representations  Depth first search.
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.
Directed Graphs Directed Graphs Shortest Path 12/7/2017 7:10 AM BOS
Directed Graphs 12/7/2017 7:15 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Graphs Lecture 19 CS2110 – Spring 2013.
Lecture 12 Graph Algorithms
Directed Graphs 9/20/2018 1:45 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Directed Graphs 5/1/15 12:25:22 PM
Directed Graphs Directed Graphs 1 Shortest Path Shortest Path
Directed Graphs (digraphs)
More Graph Algorithms.
Graphs Chapter 13.
CS223 Advanced Data Structures and Algorithms
Topological Sort CSE 373 Data Structures Lecture 19.
Graph Representation (23.1/22.1)
Chapter 11 Graphs.
Connected Components, Directed Graphs, Topological Sort
Directed Graphs Directed Graphs Directed Graphs 2/23/ :12 AM BOS
Graphs G = (V, E) V are the vertices; E are the edges.
Analysis and design of algorithm
GRAPHS.
For Friday Read chapter 9, sections 2-3 No homework
GRAPH TRAVERSAL.
Presentation transcript:

CSC 213 – Large Scale Programming

Today’s Goals  Examine new properties of DirectedGraph s  What reaching & reachable mean for a Graph  How humans go about computing these properties  Algorithms for computers to compute these  Examine what meant by DAG and why you care  Simple ways to develop schedules will be examined  How can algorithm tell when a schedule impossible

Directed Graph  Only directed edges  Replace undirected edge with 2 directed edges  Relationships go in only one direction  One-way streets  Flights  Scheduling A C E B D

Directed Graph

Directed Graph Properties  Each edge goes one-way  (a,b) connects a to b does not connect  (a,b) does not connect b to a  Can discuss in-edges & out-edges  (a,b) is out-edge for a  (a,b) is in-edge for b  Adjacency-based Graph classes can change  Use 2 Sequences for adjacency-list vertices  Define source & target dimension in adjacency-matrix incidentEdges returns both in-edges & out-edges a c e b d

Reachability  e, a, d reachable from c a c e b d f

Reachability  e, a, d reachable from c  c reaches e a c e b d f

Reachability  e, a, d reachable from c  c reaches e  c reaches e & e incident upon d, a a c e b d f

Reachability  e, a, d reachable from c  c reaches e  c reaches e & e is incident upon d, a  d, a out-edges to c only a c e b d f

Reachability  a, c, d, e, f reachable from b a c e b d f

Reachability  a, c, d, e, f reachable from b  Path exists from b to every vertex a c e b d f

Reachability  a, c, d, e, f reachable from b  Path exists from b to every vertex  Actually have multiple paths to most vertices a c e b d f

Transitive Closure of G  Transitive closure of G usually written as G* b a d c e GG*G*

Transitive Closure of G  Transitive closure of G usually written as G*  Identical vertex sets in G & G*  G & G* have different edge sets, however b a d c e GG*G* b a d c e

Transitive Closure of G  Transitive closure of G usually written as G*  Identical vertex sets in G & G*  G & G* have different edge sets, however  Edge in G* if target reachable from source in G b a d c e GG*G* b a d c e

Transitive Closure of G  Transitive closure of G usually written as G*  Identical vertex sets in G & G*  G & G* have different edge sets, however  Edge in G* if target reachable from source in G b a d c e GG*G* b a d c e

Transitive Closure of G  Transitive closure of G usually written as G*  Identical vertex sets in G & G*  G & G* have different edge sets, however  Edge in G* if target reachable from source in G b a d c e GG*G* b a d c e

Transitive Closure of G  Transitive closure of G usually written as G*  Identical vertex sets in G & G*  G & G* have different edge sets, however  Edge in G* if target reachable from source in G b a d c e GG*G* b a d c e

Transitive Closure of G  Transitive closure of G usually written as G*  Identical vertex sets in G & G*  G & G* have different edge sets, however  Edge in G* if target reachable from source in G b a d c e GG*G* b a d c e

Computing Transitive Closure  Use dynamic programming to compute this  This solution known as Floyd-Warshall Algorithm  But how fast is it?

Floyd-Warshall’s Algorithm  Number G ’s vertices from 1 to n  Algorithm will compute n directed graphs  Set G 0 =G to initialize this algorithm  Graph of transitive closure is end result ( G n = G* )  All n directed graphs have same vertices  G k contains all edges in G k-1 (and G k-2, G k-3,…, G 0 )  G k also has edge ( v i, v j ) if edges ( v i, v k ) & ( v k, v j ) in G k-1  Takes O(n 3 ) time with adjacency matrix  Better to use “brute force” if few edges exist

Floyd-Warshall’s Algorithm  Number G ’s vertices from 1 to n  Algorithm will compute n directed graphs  Set G 0 =G to initialize this algorithm  Graph of transitive closure is end result ( G n = G* )  All n directed graphs have same vertices  G k contains all edges in G k-1 (and G k-2, G k-3,…, G 0 )  G k also has edge ( v i, v j ) if edges ( v i, v k ) & ( v k, v j ) in G k-1  Takes O(n 3 ) time with adjacency matrix  Better to use “brute force” if few edges exist

Floyd-Warshall Example – G 0 V6V6 V7V7 V5V5 V4V4 V1V1 V3V3 V2V2

V6V6 V7V7 V5V5 V4V4 V3V3 V2V2

V6V6 V7V7 V5V5 V4V4 V3V3 V2V2

V6V6 V7V7 V5V5 V4V4 V3V3 V2V2

V6V6 V7V7 V5V5 V4V4 V3V3 V2V2

V6V6 V7V7 V5V5 V4V4 V1V1 V3V3 V2V2

V6V6 V7V7 V5V5 V4V4 V1V1 V3V3

V6V6 V7V7 V5V5 V4V4 V1V1 V3V3

V6V6 V7V7 V5V5 V4V4 V1V1 V2V2

V6V6 V7V7 V5V5 V4V4 V1V1 V2V2

V6V6 V7V7 V5V5 V4V4 V1V1 V2V2

V6V6 V7V7 V5V5 V4V4 V1V1 V2V2

V6V6 V7V7 V5V5 V4V4 V1V1 V2V2

V6V6 V7V7 V5V5 V1V1 V3V3 V2V2

V6V6 V7V7 V5V5 V1V1 V3V3 V2V2

V6V6 V7V7 V5V5 V1V1 V3V3 V2V2

V6V6 V7V7 V5V5 V1V1 V3V3 V2V2

V6V6 V7V7 V5V5 V1V1 V3V3 V2V2

V6V6 V7V7 V5V5 V1V1 V3V3 V2V2

V6V6 V7V7 V4V4 V1V1 V3V3 V2V2

V6V6 V7V7 V4V4 V1V1 V3V3 V2V2

V6V6 V7V7 V4V4 V1V1 V3V3 V2V2

V6V6 V7V7 V4V4 V1V1 V3V3 V2V2

V7V7 V5V5 V4V4 V1V1 V3V3 V2V2

V7V7 V5V5 V4V4 V1V1 V3V3 V2V2

V6V6 V5V5 V4V4 V1V1 V3V3 V2V2

Floyd-Warshall Example – G * V6V6 V7V7 V5V5 V4V4 V1V1 V3V3 V2V2

DAG Directed Acyclic Graph  Often called a DAG  Number & sort vertices  Topological order found  Each edge ( v i, v j ) has i < j  Finds valid schedules…  …or proves cannot exist! b a d c e G (is a DAG) b a d c e A valid ordering of G

DAG Directed Acyclic Graph  Often called a DAG  Number & sort vertices  Topological order found  Each edge ( v i, v j ) has i < j  Finds valid schedules…  …or proves cannot exist! b a d c e G (is a DAG) b a d c e Another valid ordering of G

Topological Sorting  Edges connect smaller to larger vertex numbers wake up study eat class study homework work study go to bed dream about classwork Professor’s expectation of student’s day

Topological Sort Algorithm Algorithm topologicalSort( Graph G) H  // Make a copy of G m  new Vertex[ G.numVertices() ] stack  new … Stack () // Push onto stack any vertex in H with no outgoing edges n  G.numVertices() while n ≥ 1 do v  stack.pop() n  n – 1 m[n]  v foreach e in v.incidentEdges() ≠ 0 do w  H.opposite(e, v) // Remove e from H if w has no outgoing edges then stack.push(w) return m

Topological Sorting Example

For Next Lecture  Weekly assignment out & due tomorrow  Programming assignment #3 plans due Friday  Please do not wait to start working on these ideas  For Wednesday, read &  Find quickest way to get someplace, can it be done?  How can we find the spanning tree that weighs least?