Chapter 13 Graph Algorithms

Slides:



Advertisements
Similar presentations
Request Dispatching for Cheap Energy Prices in Cloud Data Centers
Advertisements

SpringerLink Training Kit
Luminosity measurements at Hadron Colliders
From Word Embeddings To Document Distances
Choosing a Dental Plan Student Name
Virtual Environments and Computer Graphics
Chương 1: CÁC PHƯƠNG THỨC GIAO DỊCH TRÊN THỊ TRƯỜNG THẾ GIỚI
THỰC TIỄN KINH DOANH TRONG CỘNG ĐỒNG KINH TẾ ASEAN –
D. Phát triển thương hiệu
NHỮNG VẤN ĐỀ NỔI BẬT CỦA NỀN KINH TẾ VIỆT NAM GIAI ĐOẠN
Điều trị chống huyết khối trong tai biến mạch máu não
BÖnh Parkinson PGS.TS.BS NGUYỄN TRỌNG HƯNG BỆNH VIỆN LÃO KHOA TRUNG ƯƠNG TRƯỜNG ĐẠI HỌC Y HÀ NỘI Bác Ninh 2013.
Nasal Cannula X particulate mask
Evolving Architecture for Beyond the Standard Model
HF NOISE FILTERS PERFORMANCE
Electronics for Pedestrians – Passive Components –
Parameterization of Tabulated BRDFs Ian Mallett (me), Cem Yuksel
L-Systems and Affine Transformations
CMSC423: Bioinformatic Algorithms, Databases and Tools
Some aspect concerning the LMDZ dynamical core and its use
Bayesian Confidence Limits and Intervals
实习总结 (Internship Summary)
Current State of Japanese Economy under Negative Interest Rate and Proposed Remedies Naoyuki Yoshino Dean Asian Development Bank Institute Professor Emeritus,
Front End Electronics for SOI Monolithic Pixel Sensor
Face Recognition Monday, February 1, 2016.
Solving Rubik's Cube By: Etai Nativ.
CS284 Paper Presentation Arpad Kovacs
انتقال حرارت 2 خانم خسرویار.
Summer Student Program First results
Theoretical Results on Neutrinos
HERMESでのHard Exclusive生成過程による 核子内クォーク全角運動量についての研究
Wavelet Coherence & Cross-Wavelet Transform
yaSpMV: Yet Another SpMV Framework on GPUs
Creating Synthetic Microdata for Higher Educational Use in Japan: Reproduction of Distribution Type based on the Descriptive Statistics Kiyomi Shirakawa.
MOCLA02 Design of a Compact L-­band Transverse Deflecting Cavity with Arbitrary Polarizations for the SACLA Injector Sep. 14th, 2015 H. Maesaka, T. Asaka,
Hui Wang†*, Canturk Isci‡, Lavanya Subramanian*,
Fuel cell development program for electric vehicle
Overview of TST-2 Experiment
Optomechanics with atoms
داده کاوی سئوالات نمونه
Inter-system biases estimation in multi-GNSS relative positioning with GPS and Galileo Cecile Deprez and Rene Warnant University of Liege, Belgium  
ლექცია 4 - ფული და ინფლაცია
10. predavanje Novac i financijski sustav
Wissenschaftliche Aussprache zur Dissertation
FLUORECENCE MICROSCOPY SUPERRESOLUTION BLINK MICROSCOPY ON THE BASIS OF ENGINEERED DARK STATES* *Christian Steinhauer, Carsten Forthmann, Jan Vogelsang,
Particle acceleration during the gamma-ray flares of the Crab Nebular
Interpretations of the Derivative Gottfried Wilhelm Leibniz
Advisor: Chiuyuan Chen Student: Shao-Chun Lin
Widow Rockfish Assessment
SiW-ECAL Beam Test 2015 Kick-Off meeting
On Robust Neighbor Discovery in Mobile Wireless Networks
Chapter 6 并发:死锁和饥饿 Operating Systems: Internals and Design Principles
You NEED your book!!! Frequency Distribution
Y V =0 a V =V0 x b b V =0 z
Fairness-oriented Scheduling Support for Multicore Systems
Climate-Energy-Policy Interaction
Hui Wang†*, Canturk Isci‡, Lavanya Subramanian*,
Ch48 Statistics by Chtan FYHSKulai
The ABCD matrix for parabolic reflectors and its application to astigmatism free four-mirror cavities.
Measure Twice and Cut Once: Robust Dynamic Voltage Scaling for FPGAs
Online Learning: An Introduction
Factor Based Index of Systemic Stress (FISS)
What is Chemistry? Chemistry is: the study of matter & the changes it undergoes Composition Structure Properties Energy changes.
THE BERRY PHASE OF A BOGOLIUBOV QUASIPARTICLE IN AN ABRIKOSOV VORTEX*
Quantum-classical transition in optical twin beams and experimental applications to quantum metrology Ivano Ruo-Berchera Frascati.
The Toroidal Sporadic Source: Understanding Temporal Variations
FW 3.4: More Circle Practice
ارائه یک روش حل مبتنی بر استراتژی های تکاملی گروه بندی برای حل مسئله بسته بندی اقلام در ظروف
Decision Procedures Christoph M. Wintersteiger 9/11/2017 3:14 PM
Limits on Anomalous WWγ and WWZ Couplings from DØ
Presentation transcript:

Chapter 13 Graph Algorithms ORD DFW SFO LAX 802 1743 1843 1233 337 Chapter 13 Graph Algorithms Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and Mount (Wiley 2004) and slides from Nancy M. Amato And Jory Denny 1 1

Directed Graphs Shortest Path 12/7/2017 7:14 AM BOS ORD JFK SFO DFW MIA ORD LAX DFW SFO Directed Graphs

Digraphs E D C B A A digraph is a graph whose edges are all directed Short for “directed graph” Applications one-way streets flights task scheduling

Digraph Properties E D C B A A graph 𝐺=(𝑉,𝐸) such that Each edge goes in one direction: Edge (𝑎,𝑏) goes from 𝑎 to 𝑏, but not 𝑏 to 𝑎 If 𝐺 is simple, 𝑚 < 𝑛(𝑛−1) If we keep in-edges and out-edges in separate adjacency lists, we can perform listing of incoming edges and outgoing edges in time proportional to their size

Scheduling: edge (𝑎,𝑏) means task 𝑎 must be completed before 𝑏 can be started Digraph Application The good life ics141 ics131 ics121 ics53 ics52 ics51 ics23 ics22 ics21 ics161 ics151 ics171

Directed DFS A C E B D We can specialize the traversal algorithms (DFS and BFS) to digraphs by traversing edges only along their direction In the directed DFS algorithm, we have four types of edges discovery edges back edges forward edges cross edges A directed DFS starting at a vertex 𝑠 determines the vertices reachable from 𝑠

Reachability A C E B D F A C E D A C E B D F DFS tree rooted at 𝑣: vertices reachable from 𝑣 via directed paths A C E D A C E B D F A C E B D F

Strong Connectivity a g c d e b f Each vertex can reach all other vertices a d c b e f g

Strong Connectivity Algorithm Pick a vertex 𝑣 in 𝐺 Perform a DFS from 𝑣 in 𝐺 If there’s a 𝑤 not visited, print “no” Let 𝐺’ be 𝐺 with edges reversed Perform a DFS from 𝑣 in 𝐺’ Else, print “yes” Running time: 𝑂(𝑛+𝑚) g c d e b f a G’: g c d e b f

Strongly Connected Components Maximal subgraphs such that each vertex can reach all other vertices in the subgraph Can also be done in 𝑂(𝑛+𝑚) time using DFS, but is more complicated (similar to biconnectivity). a d c b e f g { a , c , g } { f , d , e , b }

Transitive Closure B A D C E G G* has the same vertices as G Given a digraph 𝐺, the transitive closure of 𝐺 is the digraph 𝐺 ∗ such that G* has the same vertices as G if 𝐺 has a directed path from 𝑢 to 𝑣 (𝑢 → 𝑣), 𝐺 ∗ has a directed edge from 𝑢 to 𝑣 The transitive closure provides reachability information about a digraph B A D C E G*

Computing the Transitive Closure If there's a way to get from A to B and from B to C, then there's a way to get from A to C. We can perform DFS starting at each vertex 𝑂(𝑛(𝑛+𝑚)) Alternatively ... Use dynamic programming: The Floyd-Warshall Algorithm

Floyd-Warshall Transitive Closure Idea #1: Number the vertices 1, 2, …,𝑛. Idea #2: Consider paths that use only vertices numbered 1, 2, …,𝑘, as intermediate vertices: Uses only vertices numbered 𝑖,…,𝑘 (add this edge if it’s not already in) i j Uses only vertices numbered 𝑖,…,𝑘−1 Uses only vertices numbered 𝑘,…,𝑗 k

Floyd-Warshall’s Algorithm Number vertices 𝑣 1 ,…, 𝑣 𝑛 Compute digraphs 𝐺 0 ,…, 𝐺 𝑛 𝐺 0 ←𝐺 𝐺 𝑘 has directed edge 𝑣 𝑖 , 𝑣 𝑗 if 𝐺 has a directed path from 𝑣 𝑖 to 𝑣 𝑗 We have that 𝐺 𝑛 = 𝐺 ∗ In phase 𝑘, digraph 𝐺 𝑘 is computed from 𝐺 𝑘−1 Running time: 𝑂 𝑛 3 , assuming 𝐺.areAdjacent 𝑣 𝑖 , 𝑣 𝑗 is 𝑂 1 (e.g., adjacency matrix) Algorithm FloydWarshall(𝐺) Input: Digraph 𝐺 Output: Transitive Closure 𝐺 ∗ of 𝐺 Name each vertex 𝑣∈𝐺.vertices( ) with 𝑖= 1…𝑛 𝐺 0 ←𝐺 for 𝑘←1…𝑛 do 𝐺 𝑘 ← 𝐺 𝑘−1 for 𝑖←1…𝑛 | 𝑖≠𝑘 do for 𝑗←1…𝑛 | 𝑗≠𝑖,𝑘 do if 𝐺 𝑘−1 .areAdjacent 𝑣 𝑖 , 𝑣 𝑘 ∧ 𝐺 𝑘−1 .areAdjacent 𝑣 𝑘 , 𝑣 𝑗 ∧ ¬ 𝐺 𝑘 .areAdjacent 𝑣 𝑖 , 𝑣 𝑗 then 𝐺 𝑘 .insertDirectedEdge v i , v j return 𝐺 𝑛

Floyd-Warshall Example JFK BOS MIA ORD LAX DFW SFO v 2 1 3 4 5 6

Floyd-Warshall, Iteration 1 JFK BOS MIA ORD LAX DFW SFO v 2 1 3 4 5 6

Floyd-Warshall, Iteration 2 JFK BOS MIA ORD LAX DFW SFO v 2 1 3 4 5 6

Floyd-Warshall, Iteration 3 JFK BOS MIA ORD LAX DFW SFO v 2 1 3 4 5 6

Floyd-Warshall, Iteration 4 JFK BOS MIA ORD LAX DFW SFO v 2 1 3 4 5 6

Floyd-Warshall, Iteration 5 JFK MIA ORD LAX DFW SFO v 2 1 3 4 5 6 BOS

Floyd-Warshall, Iteration 6 JFK MIA ORD LAX DFW SFO v 2 1 3 4 5 6 BOS

Floyd-Warshall, Conclusion JFK MIA ORD LAX DFW SFO v 2 1 3 4 5 6 BOS

DAGs and Topological Ordering B A D C E DAG G A directed acyclic graph (DAG) is a digraph that has no directed cycles A topological ordering of a digraph is a numbering 𝑣 1 ,…, 𝑣 𝑛 Of the vertices such that for every edge 𝑣 𝑖 , 𝑣 𝑗 , we have 𝑖<𝑗 Example: in a task scheduling digraph, a topological ordering a task sequence that satisfies the precedence constraints Theorem - A digraph admits a topological ordering if and only if it is a DAG B A D C E Topological ordering of G v1 v2 v3 v4 v5

Exercise Topological Sorting write c.s. program play wake up eat nap study computer sci. more c.s. work out sleep dream about graphs A typical student day bake cookies Number vertices, so that 𝑢,𝑣 in 𝐸 implies 𝑢<𝑣

Exercise Topological Sorting write c.s. program play wake up eat nap study computer sci. more c.s. work out sleep dream about graphs A typical student day 1 2 3 4 5 6 7 8 9 10 11 bake cookies Number vertices, so that 𝑢,𝑣 in 𝐸 implies 𝑢<𝑣

Algorithm for Topological Sorting Note: This algorithm is different than the one in the book Algorithm TopologicalSort 𝐺 𝐻←𝐺 𝑛←𝐺.numVertices while ¬𝐻.empty do Let 𝑣 be a vertex with no outgoing edges Label 𝑣←𝑛 𝑛←𝑛−1 𝐻.eraseVertex 𝑣

Implementation with DFS Simulate the algorithm by using depth-first search 𝑂(𝑛+𝑚) time. Algorithm topologicalDFS 𝐺 Input: DAG 𝐺 Output: Topological ordering of 𝑔 𝑛←𝐺.numVertices Initialize all vertices as 𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷 for each vertex 𝑣∈𝐺.vertices do if 𝑣.getLabel =𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷 then topologicalDFS 𝐺, 𝑣 Algorithm topologicalDFS 𝐺,𝑣 Input: DAG 𝐺, start vertex 𝑣 Output: Labeling of the vertices of 𝐺 in the connected component of 𝑣 𝑣.setLabel(𝑉𝐼𝑆𝐼𝑇𝐸𝐷) for each 𝑒∈𝑣.outEdges do 𝑤←𝑒.dest( ) if 𝑤.getLabel =𝑈𝑁𝐸𝑋𝑃𝐿𝑂𝑅𝐸𝐷 then //𝑒 is a discovery edge topologicalDFS 𝐺, 𝑤 else //𝑒 is a forward, cross, or back edge Label 𝑣 with topological number 𝑛 𝑛←𝑛−1

Topological Sorting Example

Topological Sorting Example 9

Topological Sorting Example 8 9

Topological Sorting Example 7 8 9

Topological Sorting Example 7 8 6 9

Topological Sorting Example 7 8 5 6 9

Topological Sorting Example 7 4 8 5 6 9

Topological Sorting Example 7 4 8 5 6 3 9

Topological Sorting Example 2 7 4 8 5 6 3 9

Topological Sorting Example 2 7 4 8 5 6 1 3 9