UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lectures 3 Tuesday, 9/25/01 Graph Algorithms: Part 1 Shortest.

Slides:



Advertisements
Similar presentations
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Advertisements

Comp 122, Fall 2004 Elementary Graph Algorithms. graphs Lin / Devi Comp 122, Fall 2004 Graphs  Graph G = (V, E) »V = set of vertices »E = set of.
Tirgul 7 Review of graphs Graph algorithms: –DFS –Properties of DFS –Topological sort.
Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 22.
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.
1 Dijkstra’s Minimum-Path Algorithm Minimum Spanning Tree CSE Lectures 20 – Intro to Graphs.
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 Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 23 Minimum Spanning Trees
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Chapter 23: Graph Algorithms Chapter 24: Minimum Spanning Trees.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Makeup Lecture Chapter 23: Graph Algorithms Depth-First SearchBreadth-First.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Lecture 4 Tuesday, 2/19/02 Graph Algorithms: Part 2 Network.
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
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.
Shortest Path Problems
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2008 Lecture 4 Tuesday, 9/30/08 Graph Algorithms: Part 1 Shortest.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2006 Lecture 2 Monday, 2/6/06 Design Patterns for Optimization.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2002 Lecture 2 Tuesday, 9/10/02 Design Patterns for Optimization.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2006 Lecture 2 Monday, 9/13/06 Design Patterns for Optimization Problems.
Graph COMP171 Fall Graph / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D E A C F B Vertex Edge.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Wednesday, 9/26/01 Graph Basics.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2002 Monday, 12/2/02 Design Patterns for Optimization Problems Greedy.
Graph Algorithms: Part 1
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 4 Tuesday, 10/2/01 Graph Algorithms: Part 2 Network.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Lecture 15: Depth First Search Shang-Hua Teng. Graphs G= (V,E) B E C F D A B E C F D A Directed Graph (digraph) –Degree: in/out Undirected Graph –Adjacency.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2008 Lecture 2 Tuesday, 9/16/08 Design Patterns for Optimization.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2004 Lecture 5 Wednesday, 10/6/04 Graph Algorithms: Part 2.
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.
Dijkstra's algorithm.
Graphs – Shortest Path (Weighted Graph) ORD DFW SFO LAX
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
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
Charles Lin. Graph Representation Graph Representation DFS DFS BFS BFS Dijkstra Dijkstra A* Search A* Search Bellman-Ford Bellman-Ford Floyd-Warshall.
SPANNING TREES Lecture 21 CS2110 – Spring
Chapter 2 Graph Algorithms.
Graphs, BFS, DFS and More…
1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.
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.
Elementary Graph Algorithms CLRS Chapter 22. Graph A graph is a structure that consists of a set of vertices and a set of edges between pairs of vertices.
Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph. Want to compute a shortest path for each possible.
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.
Kruskal’s and Dijkstra’s Algorithm.  Kruskal's algorithm is an algorithm in graph theory that finds a minimum spanning tree for a connected weighted.
CSE 2331 / 5331 Topic 12: Shortest Path Basics Dijkstra Algorithm Relaxation Bellman-Ford Alg.
Shortest Path Algorithms. Definitions Variants  Single-source shortest-paths problem: Given a graph, finding a shortest path from a given source.
Lecture 11 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
1 Chapter 22 Elementary Graph Algorithms. 2 Introduction G=(V, E) –V = vertex set –E = edge set Graph representation –Adjacency list –Adjacency matrix.
Runtime O(VE), for +/- edges, Detects existence of neg. loops
Weighted Graphs Computing 2 COMP s1 Sedgewick Part 5: Chapter
Chapter 22: Elementary Graph Algorithms
Graphs Part II Lecture 7. Lecture Objectives  Topological Sort  Spanning Tree  Minimum Spanning Tree  Shortest Path.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
All-Pairs Shortest Paths
DATA STRUCTURES AND ALGORITHMS Lecture Notes 10 Prepared by İnanç TAHRALI.
Shahed University Dr. Shahriar Bijani May  A path is a sequence of vertices P = (v 0, v 1, …, v k ) such that, for 1 ≤ i ≤ k, edge (v i – 1, v.
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.
Main Index Contents 11 Main Index Contents Graph Categories Graph Categories Example of Digraph Example of Digraph Connectedness of Digraph Connectedness.
Graphs David Kauchak cs302 Spring Admin HW 12 and 13 (and likely 14) You can submit revised solutions to any problem you missed Also submit your.
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.
Chapter 22: Elementary Graph Algorithms Overview: Definition of a graph Representation of graphs adjacency list matrix Elementary search algorithms breadth-first.
Graphs Lecture 18 CS2110 – Fall 2009.
Graph Algorithms: Part 1
Text Book: Introduction to algorithms By C L R S
Chapter 16 1 – Graphs Graph Categories Strong Components
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lectures 3 Tuesday, 9/25/01 Graph Algorithms: Part 1 Shortest Paths

Graph Review Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths

Introductory Graph Concepts ä G= (V,E) ä Vertex Degree ä Self-Loops B E C F D A B E C F D A ä Directed Graph (digraph) ä Degree: in/out ä Self-Loops allowed ä Undirected Graph ä No Self-Loops ä Adjacency is symmetric This treatment follows textbook Cormen et al. Some definitions differ slightly from other graph literature.

Introductory Graph Concepts: Representations B E C F D A B E C F D A ä Undirected Graph ä Directed Graph (digraph) A B C D E F ABCDEF ABCDEF A BC B ACEF C AB D E E BDF F BE A BC B CEF C D D E BD F E Adjacency Matrix Adjacency List Adjacency Matrix Adjacency List This treatment follows textbook Cormen et al. Some definitions differ slightly from other graph literature.

Introductory Graph Concepts: Paths, Cycles ä Path: ä length: number of edges ä simple: all vertices distinct ä Cycle: ä Directed Graph: ä forms cycle if v 0 =v k and k>=1 ä simple cycle: v 1,v 2..,v k also distinct ä self-loop is cycle of length 1 ä Undirected Graph: ä forms (simple) cycle if v 0 =v k and k>=3 ä simple cycle: v 1,v 2..,v k also distinct B E C F D A path path B E C F D A simple cycle simple cycle This treatment follows textbook Cormen et al. Some definitions differ slightly from other graph literature. B E C F D A simple cycle = simple cycle = most of our cycle work will be for directed graphs

Introductory Graph Concepts: Connectivity ä Undirected Graph: connected ä every pair of vertices is connected by a path ä one connected component ä connected components: ä equivalence classes under “is reachable from” relation ä Directed Graph: strongly connected ä every pair of vertices is reachable from each other ä one strongly connected component ä strongly connected components: ä equivalence classes under “mutually reachable” relation B E C F D A B E C F D Aconnected 2 connected components not strongly connected strongly connected component B E C F D A B E C F D A This treatment follows textbook Cormen et al. Some definitions differ slightly from other graph literature.

SEARCHING Elementary Graph Algorithms: SEARCHING: DFS, BFS ä Breadth-First-Search (BFS): ä Shortest Path Distance ä From source to each reachable vertex ä Record during traversal ä Foundation of many “shortest path” algorithms See DFS, BFS Handout for PseudoCode ä Depth-First-Search (DFS): ä Encountering, finishing times ä “well-formed” nested (( )( ) ) structure ä Every edge of G is either a tree edge of a back edge ä EdgeColor of vertex when first tested determines edge type for unweighted directed or undirected graph G=(V,E) Time: O(|V| + |E|) adj listO(|V| 2 ) adj matrix predecessor subgraph = forest of spanning trees Vertex color shows status: not yet encountered encountered, but not yet finished finished See DFS/BFS slide show

Elementary Graph Algorithms: DFS, BFS ä Review problem: TRUE or FALSE? ä The tree shown below on the right can be a DFS tree for some adjacency list representation of the graph shown below on the left. B E C F D A A C B E D F Tree Edge Cross Edge Back Edge

Elementary Graph Algorithms: Topological Sort source: textbook Cormen et al. TOPOLOGICAL-SORT(G) 1 DFS(G) computes “finishing times” for each vertex 2 as each vertex is finished, insert it onto front of list 3 return list for Directed, Acyclic Graph (DAG) G=(V,E) Produces linear ordering of vertices. For edge (u,v), u is ordered before v. See also DFS/BFS slide show

Minimum Spanning Tree: Greedy Algorithms A B C D E F G source: textbook Cormen et al. for Undirected, Connected, Weighted Graph G=(V,E) Produces minimum weight tree of edges that includes every vertex. Invariant: Minimum weight spanning forest Becomes single tree at end Invariant: Minimum weight tree Spans all vertices at end Time: O(|E|lg|E|) given fast FIND-SET, UNION Time: O(|E|lg|V|) = O(|E|lg|E|) slightly faster with fast priority queue

Minimum Spanning Trees ä Review problem: ä For the undirected, weighted graph below, show 2 different Minimum Spanning Trees. Draw each using one of the 2 graph copies below. Thicken an edge to make it part of a spanning tree. What is the sum of the edge weights for each of your Minimum Spanning Trees? A B C D E F G

Shortest Paths Chapters 25 & 26

BFS as a Basis for Shortest Path Algorithms Source/Sink Shortest Path Problem: Given 2 vertices u, v, find the shortest path in G from u to v. Solution: BFS starting at u. Stop at v. Single-Source Shortest Paths Problem: Given a vertex u, find the shortest path in G from u to each vertex. Solution: BFS starting at u. Full BFS tree. source: based on Sedgewick, Graph Algorithms BFS for unweighted, undirected graph G=(V,E) Time: O(|V| + |E|) adj list O(|V| 2 ) adj matrix O(|V| 2 ) adj matrix Time: O(|V|(|V| + |E|)) adj list O(|V| 3 ) adj matrix O(|V| 3 ) adj matrix All-Pairs Shortest Paths Problem: Find the shortest path in G from each vertex u to each vertex v. Solution: For each u: BFS starting at u; full BFS tree.

Shortest Path Applications ä Road maps ä Airline routes ä Telecommunications network routing ä VLSI design routing Weight ~ Cost ~ Distance source: based on Sedgewick, Graph Algorithms for weighted, directed graph G=(V,E)

Transitive Closure (Matrix) source: Sedgewick, Graph Algorithms Transitive Closure Graph contains edge (u,v) if there exists a directed path in G from u to v. G

Transitive Closure (Matrix) source: Sedgewick, Graph Algorithms Boolean Matrix Product: and, or replace +,* self-loops G G2G2  22

Transitive Closure (Matrix) source: Sedgewick, Graph Algorithms 22  33 44 Algorithm 1: Find ,  ,  ,...,   V  Algorithm 2: Find ,  ,  ,...,   V  Algorithm 3: [Warshall] for i 0 to |V|-1 for s 0 to |V|-1 for s 0 to |V|-1 for t 0 to |V|-1 for t 0 to |V|-1 if  [s][i] and  [i][t] then  [s][t] 1 Time: O(|V| 3 ) Time: O(|V| 4 ) Time: O(|V| 3 lg|V|)

Transitive Closure (Matrix) source: Sedgewick, Graph Algorithms Warshall good for dense graphs

Transitive Closure (Matrix) ä HW#2: ä Update transitive closure when new edge is added to graph. ä What does the following matrix (the nxn form of it) used in shortest-path algorithms correspond to in regular matrix multiplication?

Shortest Path Trees source: Sedgewick, Graph Algorithms Shortest Path Tree gives shortest path from root to each other vertex

All Shortest Paths source: Sedgewick, Graph Algorithms

Shortest Path Principles: Relaxation ä “Relax” a constraint to try to improve solution ä “Rubber band” analogy [Sedgewick] ä Relaxation of an Edge (u,v): ä test if shortest path to v [found so far] can be improved by going through u A B C D E F G

Shortest Path Trees source: Sedgewick, Graph Algorithms

All Shortest Paths (Compact) source: Sedgewick, Graph Algorithms

All Shortest Paths In a Network source: Sedgewick, Graph Algorithms

Single Source Shortest Paths Bellman-Ford source: textbook Cormen et al. for (negative) weighted, directed graph G=(V,E) with no negative-weight cycles Time is in O(|V||E|) detect negative- weight cycle (board example)

Bellman-Ford source: Sedgewick, Graph Algorithms for (negative) weighted, directed graph G=(V,E) with no negative-weight cycles HW#2: How many iterations until each distance stops changing?

Bellman-Ford source: textbook Cormen et al. for (negative) weighted, directed graph G=(V,E) with no negative-weight cycles

Single Source Shortest Paths Dijkstra’s Algorithm source: textbook Cormen et al. for (nonnegative) weighted, directed graph G=(V,E)

Single Source Shortest Paths Dijkstra’s Algorithm ä See ShortestPath slide show A B C D E F G source: textbook Cormen et al. for (nonnegative) weighted, directed graph G=(V,E)

Single Source Shortest Paths Dijkstra’s Algorithm ä Review problem: ä ä For the directed, weighted graph below, find the shortest path that begins at vertex A and ends at vertex F. List the vertices in the order that they appear on that path. What is the sum of the edge weights of that path? A B C D E F G Why can’t Dijkstra’s algorithm handle negative-weight edges? (board example)

Single Source Shortest Paths Dijkstra’s Algorithm source: Sedgewick, Graph Algorithms for (nonnegative) weighted, directed graph G=(V,E)

All-Pairs Shortest Paths source: textbook Cormen et al. for (negative) weighted, directed graph G=(V,E) with no negative-weight cycles similar to Transitive Closure Algorithm 1 Time: O(|V| 4 )

All-Pairs Shortest Paths source: textbook Cormen et al. similar to Transitive Closure Algorithm 2 Time: O(|V| 3 lg|V|)

All-Pairs Shortest Paths source: textbook Cormen et al. HW#2: How can output be used to detect a negative- weight cycle? Can have negative- weight edges similar to Transitive Closure Algorithm 3 [Warshall] Time: O(|V| 3 )

Shortest Path Algorithms source: Sedgewick, Graph Algorithms

Graph Algorithms Research Case Study

Case Study Literature Wu, Li [1999]

Network Flow Chapter 27

Network Flow source: Sedgewick, Graph Algorithms

Controlling Network Flow source: Sedgewick, Graph Algorithms

Augmenting Flow on a Path source: Sedgewick, Graph Algorithms

Augmenting Path Sequences source: Sedgewick, Graph Algorithms