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.

Slides:



Advertisements
Similar presentations
Cpt S 223 – Advanced Data Structures Graph Algorithms: Introduction
Advertisements

Weighted graphs Example Consider the following graph, where nodes represent cities, and edges show if there is a direct flight between each pair of cities.
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Chapter 6. Konigsberg Bridge Problem A river Pregel flows around the island Keniphof and then divides into two. Four land areas A, B, C, D have this river.
Lecture 17 Path Algebra Matrix multiplication of adjacency matrices of directed graphs give important information about the graphs. Manipulating these.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
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.
CS 206 Introduction to Computer Science II 11 / 11 / Veterans Day Instructor: Michael Eckmann.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Graph & BFS.
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Design and Analysis of Algorithms - Chapter 81 Dynamic Programming Dynamic Programming is a general algorithm design technique Dynamic Programming is a.
1 Graph Introduction Definitions. 2 Definitions I zDirected Graph (or Di-Graph) is an ordered pair G=(V,E) such that yV is a finite, non-empty set (of.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
CS 206 Introduction to Computer Science II 11 / 03 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 03 / 25 / 2009 Instructor: Michael Eckmann.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Discrete Math for CS Chapter 8: Directed Graphs. Discrete Math for CS digraph: A digraph is a graph G = (V,E) where V is a finite set of vertices and.
More Graph Algorithms Weiss ch Exercise: MST idea from yesterday Alternative minimum spanning tree algorithm idea Idea: Look at smallest edge not.
Tirgul 7 Review of graphs Graph algorithms: – BFS (next tirgul) – DFS – Properties of DFS – Topological sort.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
GRAPHS Education is what remains after one has forgotten what one has learned in school. Albert Einstein Albert Einstein Smitha N Pai.
1 Graphs Algorithms Sections 9.1, 9.2, and Graphs v1v1 v2v2 v5v5 v7v7 v8v8 v3v3 v6v6 v4v4 A graph G = (V, E) –V: set of vertices (nodes) –E: set.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
1 Chapter 9 Graph Algorithms Real-life graph problems Algorithms for some graph problems Choice of data structures for graph problems.
ساختمانهای گسسته دانشگاه صنعتی شاهرود – اردیبهشت 1392.
Chapter 2 Graph Algorithms.
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Chapter 4 Relations and Digraphs
1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.
Graph Algorithms. Definitions and Representation An undirected graph G is a pair (V,E), where V is a finite set of points called vertices and E is a finite.
Graphs. What is a graph? A data structure that consists of a set of nodes (vertices) and a set of edges that relate the nodes to each other The set of.
Introduction to Graphs. Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected.
 What is a graph? What is a graph?  Directed vs. undirected graphs Directed vs. undirected graphs  Trees vs graphs Trees vs graphs  Terminology: Degree.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
1 CS104 : Discrete Structures Chapter V Graph Theory.
1 The Floyd-Warshall Algorithm Andreas Klappenecker.
The all-pairs shortest path problem (APSP) input: a directed graph G = (V, E) with edge weights goal: find a minimum weight (shortest) path between every.
COSC 2007 Data Structures II Chapter 14 Graphs I.
CS 61B Data Structures and Programming Methodology Aug 5, 2008 David Sun.
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.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
GRAPHS. Graph Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component, spanning tree Types of graphs: undirected,
All-Pairs Shortest Paths
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
Graphs Upon completion you will be able to:
Properties and Applications of Depth-First Search Trees and Forests
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Chapter 05 Introduction to Graph And Search Algorithms.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
Main Index Contents 11 Main Index Contents Graph Categories Graph Categories Example of Digraph Example of Digraph Connectedness of Digraph Connectedness.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
Lecture 20. Graphs and network models 1. Recap Binary search tree is a special binary tree which is designed to make the search of elements or keys in.
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,
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,
CS120 Graphs.
Directed Graphs Directed Graphs 1 Shortest Path Shortest Path
Graph Algorithm.
Graphs Chapter 13.
CS223 Advanced Data Structures and Algorithms
Directed Graphs Directed Graphs Directed Graphs 2/23/ :12 AM BOS
Graph Algorithms "A charlatan makes obscure what is clear; a thinker makes clear what is obscure. " - Hugh Kingsmill CLRS, Sections 22.2 – 22.4.
CS 584 Project Write up Poster session for final Due on day of final
Graphs G = (V, E) V are the vertices; E are the edges.
Presentation transcript:

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 of distinct edges. If (v, w)  E, then v is called the tail, and w is called the head of (v,w). We denote edges by v  w. Example 1: Graphs for expressing a precedence relation in scheduling applications. CS1CS2CS4CS3CS7CS6CS5

In Example 1, the precedence relation must satisfy the following conditions: 1.Irreflexivity, i.e. for all s  S, s -/-> s. 2.Asymmetry, i.e. for all s, t  S, if s  t, then t -/-> s. 3.Transitivity, i.e. for all s, r, t  S, if r  s and s  t, then r  t. where S is a set of vertices. Property: In a directed acyclic graph, for all s, t  S, s  t iff there is a path from s to t.

Example 2. Graph for expressing a binary relation. Let S = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, and R: y  x iff x  y and x divides y

Depth-first search in directed graphs Same as in undirected graphs, but the result is a depth-first search forest, rather than a tree. Example to be distributed in class.

Transitive closure of a graph The problem: Given a directed graph, G = (V, E), find all of the vertices reachable from a given starting vertex v  V. Transitive closure (definition): Let G = (V, E) be a graph, where x  y, y  z (x, y, z  V). Then we can add a new edge x  z. A graph containing all of the edges of this nature is called the transitive closure of the original graph. The best way to represent the transitive closure graph (TCG) is by means of an adjacency matrix. To generate the TCG, we can use the Warshall's algorithm: for y := 1 to NumberOfNodes { for x := 1 to NumberOfNodes { if A[x,y] then { for z := 1 to NumberOfNodes if A[y,z] then A[x,z] := True } } } Efficiency result: Warshall's algorithm solves the transitive closure problem in O(NumberOfNodes^3) time. Example to be distributed in class.

The all shortest path problem The problem: Given a weighted directed graph, G = (V, E, W), find the shortest path between all pairs of vertices from V. Solution 1: Run Dijkstra's shortest path algorithm V^2 times, each time with a new starting and destination vertex. The overall efficiency of this solution will be O(NumberOfNodes^4). Solution 2: Floyd's all-pairs shortest path algorithm. Example. Distance matrix:  3 

Example (contd.) The distance matrix is computed as follows: 0, if i = j. Distance[i, j] = EdgeWeight(i, j). , otherwise. Floyd's algorithm computes a sequence of distance matrices, such that at each step k of the computation process (1  k  NumberOfNodes), Distance[i,j] satisfies the following two criteria: 1.The path starts at vertex i, and ends at vertex j. 2.Internal vertices on the path come from the set of vertices having index values between 1 and k inclusive. In our example, the computation process is carried out as follows: Step 1: Consider all paths, which contain node 1 as an internal node, i.e. 2 --> 1 --> W(2,1) = W(1,3) = d(2,3) = 8 <  3  2 0

Example (contd.) Step 2: Consider all paths, which contain node 2 as an internal node, i.e. 3 --> 2 --> W(3,2) = W(2,1) = d(3,1) = 5 <  Step 3: Consider all path, which contain node 3 as an internal node, i.e. 1 --> 3 --> W(1,3) = W(3,2) = d(1,2) = 7 < 8

Floyd's algorithm (contd.) for k := 1 to NumberOfNodes { for i := 1 to NumberOfNodes { for j := 1 to NumberOfNodes { Distance[i,j] := min (Distance[i,j], Distance[i,k] + Distance[k,j]) } } } Efficiency result: Floyd's algorithm solves the all shortest paths problem in O(NumberOfNodes^3) time.

Topological ordering on directed acyclic graphs The problem: Given a directed acyclic graph (DAG), G = (V, E), define a linear sequence in which graph nodes can be visited. Example. Here such sequences are:  CS1 CS2 CS3 CS4 CS5 CS6 CS7 These are called “topological  CS2 CS1 CS5 CS4 CS3 CS6 CS7 orderings” of the graph’s nodes.  CS6 CS2 CS5 CS1 CS1 CS3 CS7  and so on… CS1 CS2 CS4 CS7 CS6 CS5 CS3

Definition. The indegree of a graph node is the number of edges entering the node, and the outdegree of a graph node is the number of edges exiting from the node. Topological ordering algorithm: ComputeInitialIndegree (G, Indegree) for n := 1 to NumberOfNodes if Indegree[n] = 0 then enqueue (ZeroQ, n) orderCount := 0 while (! Empty (ZeroQ)) { v := dequeue(ZeroQ) orderCount := orderCount + 1; T[orderCount] := v for n := 1 to NumberOfNodes if (edge (v, n)) then Indegree[n] := Indegree[n] – 1 if (Indegree[n] = 0) then enqueue(ZeroQ) Efficiency result: ComputeInitialIndegree is O(NumberOfNodes^2) operation, therefore total efficiency of topological ordering is O(NumberOfNodes^2).