School of Computing Clemson University Fall, 2012

Slides:



Advertisements
Similar presentations
Great Theoretical Ideas in Computer Science
Advertisements

Graphs and Finding your way in the wilderness
CS38 Introduction to Algorithms Lecture 2 April 3, 2014.
Cpt S 223 – Advanced Data Structures Graph Algorithms: Introduction
2012: J Paul GibsonT&MSP: Mathematical FoundationsMAT7003/L2-GraphsAndTrees.1 MAT 7003 : Mathematical Foundations (for Software Engineering) J Paul Gibson,
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
Connected Components, Directed Graphs, Topological Sort COMP171.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
CS/ENGRD 2110 Object-Oriented Programming and Data Structures Fall 2014 Doug James Lecture 17: Graphs.
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.
Graph Algorithms Using Depth First Search Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
GRAPH Learning Outcomes Students should be able to:
IS 2610: Data Structures Graph April 5, 2004.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Lecture 13 Graphs. Introduction to Graphs Examples of Graphs – Airline Route Map What is the fastest way to get from Pittsburgh to St Louis? What is the.
Spring 2015 Lecture 10: Elementary Graph Algorithms
Computer Science 112 Fundamentals of Programming II Introduction to Graphs.
1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.
Data Structures & Algorithms Graphs
Chapter 8 Maximum Flows: Additional Topics All-Pairs Minimum Value Cut Problem  Given an undirected network G, find minimum value cut for all.
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 5.
Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)
CSE 421 Algorithms Richard Anderson Autumn 2015 Lecture 5.
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
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.
Week 11 - Wednesday.  What did we talk about last time?  Exam 2  And before that:  Graph representations  Depth first search.
Introduction to Algorithms
Breadth-First Search (BFS)
School of Computing Clemson University Fall, 2012
Graphs Lecture 19 CS2110 – Spring 2013.
Graphs Representation, BFS, DFS
Lecture 11 Graph Algorithms
GRAPHS Lecture 16 CS2110 Fall 2017.
Graph theory Definitions Trees, cycles, directed graphs.
Lectures on Network Flows
Depth-First Search.
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Community detection in graphs
CS 3343: Analysis of Algorithms
I206: Lecture 15: Graphs Marti Hearst Spring 2012.
CS120 Graphs.
Graph Algorithms Using Depth First Search
Lecture 10 Algorithm Analysis
Graph & BFS.
Graphs Representation, BFS, DFS
Graphs Lecture 18 CS2110 – Fall 2009.
Graphs Chapter 13.
Elementary graph algorithms Chapter 22
Lectures on Graph Algorithms: searching, testing and sorting
Connected Components, Directed Graphs, Topological Sort
GRAPHS Lecture 17 CS2110.
Richard Anderson Autumn 2016 Lecture 5
Richard Anderson Winter 2009 Lecture 6
Algorithms (2IL15) – Lecture 7
Text Book: Introduction to algorithms By C L R S
Chapter 16 1 – Graphs Graph Categories Strong Components
GRAPHS Lecture 17 CS2110 Spring 2018.
Elementary graph algorithms Chapter 22
Elementary Graph Algorithms
Richard Anderson Winter 2019 Lecture 6
Richard Anderson Lecture 5 Graph Theory
INTRODUCTION TO NETWORK FLOWS
Lecture 10 Graph Algorithms
Richard Anderson Winter 2019 Lecture 5
Richard Anderson Autumn 2015 Lecture 6
Graph Traversals Some applications require visiting every vertex in the graph exactly once. The application may require that vertices be visited in some.
Presentation transcript:

School of Computing Clemson University Fall, 2012 Lecture 19. Graph Algorithms, Connectivity Analysis CpSc 212: Algorithms and Data Structures Brian C. Dean School of Computing Clemson University Fall, 2012

Graphs (Networks) A graph is comprised of nodes (a.k.a. vertices) and edges. Each edge joins a pair of vertices. Graphs can be either undirected or directed; by default “graph” == “undirected graph”. Graphs are extremely common in CS and algorithms, since they can model a very wide range of problems and applications.

Graph Types Graph theorists have studied many different special types of graphs. Some simple examples of special classes of graphs we’ll tend to see include: The path (Pn) The cycle (Cn) The complete graph (Kn) Trees and forests Bipartite graphs Planar graphs

Some Classical Graph Problems [Shortest Paths]: Find the shortest path between two nodes, or from one node to all other nodes. [Minimum Spanning Trees]: Find a min-cost subset of edges that connects together all nodes. [Matchings]: Pair up as many nodes as possible, or pair up all nodes at minimum total cost. [Flow / Routing]: Route a maximum amount of some commodity through a capacitated network, possibly at minimum total cost. B A 7 15 4 9 16 19 10 11 12 3 8 14 2

Network Analysis / Data Mining [Similarity / Connectivity]: How similar are nodes X and Y if edges connect directly-related elements? [Clustering]: Does a graph break naturally into several large “clusters”? [Centrality]: Find nodes that are well-connected with all other nodes. purchases customers Y X

Terminology Walk: series of nodes connected by edges. Also fine to think of it as a sequence of edges. In a digraph, we tend to focus on directed walks. Path: a “simple” walk (visits no node twice). Cycle: a path that starts and ends at the same node. Connected components Strongly connected components in a digraph Two nodes i and j belong to the same SCC if there’s a directed path from i to j and from j to i.

Graph Representation Two main ways to represent a graph: An adjacency matrix (good for dense graphs) Adjacency lists (ideal for sparse graphs) Unless otherwise stated, we’ll assume our graphs are represented using adjacency lists. 1 2 3 4 1 0 1 0 0 2 0 0 1 0 3 1 0 0 1 4 0 0 1 0 1 2 3 4 1 1: 2 3 2: 1 3 4 3: 1 2 4 5 4: 2 3 5 5: 3 4 2 3 4 5

Simple Connectivity Questions Some of the most fundamental graph algorithms related to issues of connectivity: Are nodes i and j connected by some path? If so, determine such a path. In a digraph, is there a directed path from i to j? Does a (directed) graph have a (directed) cycle? Partition a graph into its connected components. Partition a digraph into its strongly connected components. We can answer all of these questions in linear time using a remarkably versatile algorithm known as depth-first search.

Depth-First Search (DFS) DFS-Visit(i): Status[i] = ‘visited’ For all j such that (i,j) is an edge: If Status[j] = ‘unvisited’: Pred[j] = i DFS-Visit(j) Full-DFS: For all i: Pred[i] = null, Status[i] = ‘unvisited’ For all i: If Status[i] = ‘unvisited’: DFS-Visit(i) Works in undirected and directed graphs. Full-DFS takes O(m + n) time since it spends O(1) time on each node and edge.

Depth-First Search (DFS) Full-DFS gives us an easy way to partition an undirected graph into its connected components. The pred[i] pointers define what is called a depth-first search tree. To find a path from i to j (if it exists): Intialize pred and status values for all nodes. Call DFS-Visit(i). Then follow pred pointers backward from j to i

Topological Sorting Directed Acyclic Graphs (DAGs) are often used to model systems with “precedence” constraints. Topological sorting is the process of ordering the nodes of a DAG so all edges point a consistent direction.

Topological Sorting There are several ways to topologically sort in O(m + n) time; for example: Find a node with no incoming edges, add it next to the ordering, remove it from our graph, repeat. If we ever find that every node has an incoming edge, then our graph must contain a cycle (so this gives an alternate way to do cycle detection). Depth-first search gives us another very simple topological sorting algorithm…

Topological Sorting Let’s associate with each node i a “discovery time” d[i] and a “finishing time” f[i]: DFS-Visit(i): Status[i] = ‘visited’ d[i] = current_time, Increment current_time For all j such that (i,j) is an edge: If Status[j] = ‘unvisited’: Pred[j] = i DFS-Visit(j) f[i] = current_time, Increment current_time To topologically sort a DAG, just perform a Full-DFS and then output nodes in reverse order of finishing times. We can output each node when it is “finished”, or we can sort the nodes by their finishing times (in linear time with counting sort) as a post-processing step.

Topological Sorting Claim: In a DAG with an edge from node i to node j, we will have f(i) > f(j). Proof: Consider two cases: (a) Full-DFS visits i first. (b) Full-DFS visits j first. In both cases, we have f(i) > f(j) as long as our graph contains no directed cycles (which it doesn’t, since it’s a DAG!)

Towards Higher Orders of Connectivity: The Maximum Flow Problem 10 / 10 1 2 12 / 15 10 /12 6 / 9 4 / 5 0 / 23 s t 6 / 6 8 / 8 3 4 2 / 2 Given a directed graph with capacities on edges, what is the maximum amount of flow that can be shipped from a source node s to a sink node t? 18 units

s-t Cuts An s-t cut is a partition of the node in our graph into two sets, one containing s and the other containing t. The capacity of a cut is the sum of the capacities of the edges crossing the cut in the s → t direction. 10 1 2 15 12 9 5 23 s t 6 8 3 4 2 Capacity = 10 + 9 + 2 = 21

s-t Cuts Easy observation: The value of the maximum flow is at most the capacity of any cut. So: max s-t flow value ≤ min s-t cut capacity. 10 1 2 15 12 9 5 23 s t 6 8 3 4 2 Capacity = 10 + 9 + 2 = 21

s-t Cuts Easy observation: The value of the maximum flow is at most the capacity of any cut. So: max s-t flow value ≤ min s-t cut capacity. Famous result: max s-t flow value = min s-t cut capacity. 10 1 2 15 12 9 5 23 s t 6 8 3 4 2 Capacity = 10 + 9 + 2 = 21

Higher Levels of Connectivity Minimum # of edges we need to remove to separate s and t. (minimum s-t cut) Maximum # of edge-disjoint s-t paths (path decomposition of a max flow in a graph with unit capacities) =

Higher Levels of Connectivity Let λ(x,y) denote the value of a unit-cap max flow from x to y. Equivalently, the minimum # of edge removals to separate x from y. This quantity is known as the edge connectivity between x and y. x λ(x, y) = 3 y

The Hierarchical, Nested Structure of k-Edge-Connected Components