Algorithms CSCI 235, Spring 2019 Lecture 35 Graphs IV

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Graph Algorithms
Advertisements

CSE 2331/5331 CSE 780: Design and Analysis of Algorithms Lecture 14: Directed Graph BFS DFS Topological sort.
Lecture 15. Graph Algorithms
Comp 122, Spring 2004 Graph Algorithms – 2. graphs Lin / Devi Comp 122, Fall 2004 Identification of Edges Edge type for edge (u, v) can be identified.
Greed is good. (Some of the time)
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Tirgul 7 Review of graphs Graph algorithms: –DFS –Properties of DFS –Topological sort.
Lecture 16: DFS, DAG, and Strongly Connected Components Shang-Hua Teng.
CSE 2331/5331 Topic 11: Basic Graph Alg. Representations Undirected graph Directed graph Topological sort.
Graphs II Kruse and Ryba Chapter 12. Undirected Graph Example: Subway Map.
Tirgul 11 DFS Properties of DFS Topological sort.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Makeup Lecture Chapter 23: Graph Algorithms Depth-First SearchBreadth-First.
1 Data Structures DFS, Topological Sort Dana Shapira.
Lecture 10 Topics Application of DFS Topological Sort
CSE 780 Algorithms Advanced Algorithms Graph Alg. DFS Topological sort.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Topological Sorting and Least-cost Path Algorithms.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
COSC 3101A - Design and Analysis of Algorithms 10
Spring 2015 Lecture 10: Elementary Graph Algorithms
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
Graphs David Kauchak cs302 Spring DAGs Can represent dependency graphs underwear pants belt shirt tie jacket socks shoes watch.
Jan Topological Order and SCC Edge classification Topological order Recognition of strongly connected components.
1 Chapter 22 Elementary Graph Algorithms. 2 Introduction G=(V, E) –V = vertex set –E = edge set Graph representation –Adjacency list –Adjacency matrix.
Topological Sort: Definition
1 Chapter 22: Elementary Graph Algorithms III. 2 About this lecture Topological Sort.
1 Algorithms CSCI 235, Fall 2015 Lecture 35 Graphs IV.
Lecture 19 Minimal Spanning Trees CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
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.
Graphs + Shortest Paths David Kauchak cs302 Spring 2013.
November 22, Algorithms and Data Structures Lecture XII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Introduction to Algorithms
Topological Sorting.
Chapter 22 Elementary Graph Algorithms
Main algorithm with recursion: We’ll have a function DFS that initializes, and then calls DFS-Visit, which is a recursive function and does the depth first.
Greedy Technique.
CSE 2331/5331 Topic 9: Basic Graph Alg.
Topological Sort Minimum Spanning Tree
Topological Sort (an application of DFS)
CSC 413/513: Intro to Algorithms
CS200: Algorithm Analysis
CSCE 411 Design and Analysis of Algorithms
Graph Algorithm.
Minimum-Cost Spanning Tree
Many slides here are based on E. Demaine , D. Luebke slides
CS 3343: Analysis of Algorithms
Graph Algorithms – 2 DAGs Topological order
Graph Representation Adjacency list representation of G = (V, E)
Lecture 10 Algorithm Analysis
Spanning Trees.
Graph Algorithms – 2.
Advanced Algorithms Analysis and Design
"Learning how to learn is life's most important skill. " - Tony Buzan
CSE 373 Data Structures and Algorithms
Algorithms and Data Structures Lecture XII
Minimum-Cost Spanning Tree
Graph Representation (23.1/22.1)
Minimum-Cost Spanning Tree
Kruskal’s Minimum Spanning Tree Algorithm
Analysis of Algorithms CS 477/677
CSCI2100 Data Structures Tutorial
Topological Sort (an application of DFS)
Graph Algorithms "A charlatan makes obscure what is clear; a thinker makes clear what is obscure. " - Hugh Kingsmill CLRS, Sections 22.2 – 22.4.
CSE 373: Data Structures and Algorithms
Text Book: Introduction to algorithms By C L R S
CSC 380: Design and Analysis of Algorithms
Chapter 16 1 – Graphs Graph Categories Strong Components
CSE 417: Algorithms and Computational Complexity
Minimum-Cost Spanning Tree
Chapter 22: Elementary Graph Algorithms III
Presentation transcript:

Algorithms CSCI 235, Spring 2019 Lecture 35 Graphs IV

Topological Sort A directed acyclic graph (DAG) is a directed graph without cycles. A topological sort of a DAG = (V, E) is a linear ordering of vertices in V consistent with the partial order a < b if (a, b) is in E. In other words, each vertex in a topological sort must precede all its descendants in the DAG and must follow all its ancestors. Another way to look at it: A topological sort lines up all the vertices in the DAG so that all the edges point from left to right.

Algorithm for Topological sort Topological-Sort(G) Call DFS(G) to compute the finish times v.finish for each vertex in v. As each vertex is finished, insert it into the front of a linked list. Return the linked list of vertices. Because each vertex is finished after all its descendants are finished, each vertex precedes all its descendants in the list. Running time = Running time of DFS + time to insert into list = Q(V+E) + Q(V) = Q(V + E)

Example: Professor Bumstead gets dressed Professor Bumstead must put on certain items before others (e.g. socks before shoes). socks watch undershorts shoes pants shirt We will work out the topological sort in class belt tie jacket

Connected and Strongly Connected components A connected component of a graph is a maximal set of vertices such that for any two vertices, a and b, in the set, there is a path from a to b or from b to a. In other words: two vertices are in the same connected component if there is a path from one to the other. A strongly connected component of a graph is a maximal set of vertices such that for any two vertices, a and b, in the set, there is a path from a to b and from b to a. In other words: In a strongly connected component there is a path from every member of the set to every other member of the set. Importance: Decomposing a graph into its strongly connected components is the first step in many graph algorithms.

Algorithm for strongly connected components Definition: The transpose of G, written GT, is a graph with the same vertices as G in which the directions of the edges have been reversed. Strongly-Connected-Components(G) Call DFS(G) to compute v.finish for each vertex in G. Call Modified-DFS(GT), where the main loop of Modified-DFS(GT) processes vertices in order of decreasing finish[v]. Each tree in the depth-first forest of Modified-DFS(GT) is a strongly connected component of G. Running time = running time of DFS = Q(V + E)

Example a b c d e f g h

Minimizing Distance 10 5 12 1 8 1 16 2 2 14 How can we wire together a group of towns using the minimum total length of cable so that each town is connected to the network?

The Minimum Spanning Tree Problem Given: A connected graph, G = <V, E>, such that each edge, is assigned a non-negative length (or weight). Problem: Find a subset T of E such that <V, T> remains connected, and the sum of the lengths of the edges is as small as possible subject to the above. Note: T is always acyclic. (Why?)

A Greedy Solution At each step, make a greedy choice (i.e. the choice that seems best at the time). What is greedy choice? Choose the shortest edge, x, such that our tree remains acyclic (i.e. that connects 2 components that were not previously connected).

Kruskal's Algorithm Kruskal(G, w) sort the edges by increasing weight for each edge e on the sorted list do if e does not form a cycle with the edges already taken then include e in the spanning tree else discard e return resulting edge set

Is Greed Always Good? A slightly different problem: Given: A connected graph G = <V, E> such that each edge is assigned a non-negative length. Problem: Find a subset T of E such that the edges of T form a closed path that includes every node and have the smallest possible total weight. 1000 2 1 1 2 1