Directed Graphs (Yonlu Graflar)

Slides:



Advertisements
Similar presentations
Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Advertisements

1 A B C
Scenario: EOT/EOT-R/COT Resident admitted March 10th Admitted for PT and OT following knee replacement for patient with CHF, COPD, shortness of breath.
Variations of the Turing Machine
Angstrom Care 培苗社 Quadratic Equation II
AP STUDY SESSION 2.
1
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
David Burdett May 11, 2004 Package Binding for WS CDL.
and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Properties of Real Numbers CommutativeAssociativeDistributive Identity + × Inverse + ×
Local Customization Chapter 2. Local Customization 2-2 Objectives Customization Considerations Types of Data Elements Location for Locally Defined Data.
Process a Customer Chapter 2. Process a Customer 2-2 Objectives Understand what defines a Customer Learn how to check for an existing Customer Learn how.
Custom Services and Training Provider Details Chapter 4.
CALENDAR.
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt BlendsDigraphsShort.
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt RhymesMapsMathInsects.
1 Click here to End Presentation Software: Installation and Updates Internet Download CD release NACIS Updates.
1. PHOTO INDEX Bayside: Page 5-7 Other Colour Leon: Page 8-10 Cabrera Page Canaria Page Driftwood Page 16 Florence Florence and Corfu Page.
Break Time Remaining 10:00.
Turing Machines.
Table 12.1: Cash Flows to a Cash and Carry Trading Strategy.
PP Test Review Sections 6-1 to 6-6
Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence.
1 The Blue Café by Chris Rea My world is miles of endless roads.
Bright Futures Guidelines Priorities and Screening Tables
Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation 1.
Bellwork Do the following problem on a ½ sheet of paper and turn in.
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.
Exarte Bezoek aan de Mediacampus Bachelor in de grafische en digitale media April 2014.
TESOL International Convention Presentation- ESL Instruction: Developing Your Skills to Become a Master Conductor by Beth Clifton Crumpler by.
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
Graphs, representation, isomorphism, connectivity
Adding Up In Chunks.
MaK_Full ahead loaded 1 Alarm Page Directory (F11)
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt Synthetic.
Artificial Intelligence
Before Between After.
Subtraction: Adding UP
: 3 00.
5 minutes.
1 En kisa yollarin bulunmasi Verilen bir undirected (yonsuz) graf ve kaynak vertex s, bir yol (path) in uzunlugu bu yol uzerindeki edge (kenar) lerin sayisidir.
1 hi at no doifpi me be go we of at be do go hi if me no of pi we Inorder Traversal Inorder traversal. n Visit the left subtree. n Visit the node. n Visit.
1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
Types of selection structures
Speak Up for Safety Dr. Susan Strauss Harassment & Bullying Consultant November 9, 2012.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Converting a Fraction to %
Numerical Analysis 1 EE, NCKU Tien-Hao Chang (Darby Chang)
Clock will move after 1 minute
PSSA Preparation.
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
Physics for Scientists & Engineers, 3rd Edition
Energy Generation in Mitochondria and Chlorplasts
Select a time to count down from the clock above
Copyright Tim Morris/St Stephen's School
1.step PMIT start + initial project data input Concept Concept.
1 Decidability continued…. 2 Theorem: For a recursively enumerable language it is undecidable to determine whether is finite Proof: We will reduce the.
More on Dynamic Programming Bellman-FordFloyd-Warshall Wednesday, July 30 th 1.
Bioinformatics Programming 1 EE, NCKU Tien-Hao Chang (Darby Chang)
Presentation transcript:

Directed Graphs (Yonlu Graflar) Directed graph (digraph) G=(V,E) V: vertices (nodes) E: edges (directed edges,arcs) 1 2 4 3 Algoritma Analizi

path Bir digraftaki path bir dizi vertices den olusur oyleki bir birini izleyen iki vertex arasinda bir edge var v1->v2->v3 ……… ->vn-1->vn vertex v1 den vertex vn e bir path (yol) Length of path (yolun uzunlugu) Path uzerindeki arc larin sayisi v den v ye (v bir vertex) olan yolun uzunlugu 0 dir Simple path: Eger path in uzerindeki tum vertices (ilk ve son vertex ler haric) farkli ise Algoritma Analizi

Labeled Digraph Bazen graph in vertices veya arc larina faydali bilgiler (label) eklemek mumkun Label isim, maliyet veya faydali herhangi bir bilgi olabilir. Algoritma Analizi

Labeled Digraph 1 2 3 4 b a Algoritma Analizi

Directed Graph larin Temsili Digraph lari temsil etmek icin cesitli data structure lar kullanilabilir Secilen data structure arc lara ve vertices lara uygulanan operationlara baglidir Adjacency Matrix Adjacency List Algoritma Analizi

Adjacency Matrix G = (V,E), V={1,2,3, ………n} G nin Adjacency Matrix A A nxn boyutlu bir boolean matrix A[i,j] = true ancak ve ancak vi den vj ye bir arc var Bazen true 1 le false 0 ile temsil edilir Labeled Adjacency Matrix A[i,j] vi den vj giden arc in label ini gosterir Algoritma Analizi

1 2 3 4 b a 1 2 3 4 a b Digraph Adjacency Matrix Algoritma Analizi

Adjacency List Adjacency matrix kullaniminin dezavantaji storage Matrix uzerinde islem O(n) arc a sahip digraphlar icin O(n2) den daha iyi performansli algoritmalarin elde edilmesini imkansizlastirir Bu dezavantajlari gidermek icin Adjacency List kullanilabilir Algoritma Analizi

Adjacency List G = (V,E) HEAD Storage Dezavantaj HEAD[i] vertex i icin Adjacency List e bir pointer Storage Vertices lerin sayi artisi arc larin sayisiyle orantilidir Dezavantaj Vertex i den vertex j ye bir arc olup olmadigini tespit etmek icin O(n) zaman gerekli Algoritma Analizi

Adjacency List 1 2 4 3 2 1 3 2 4 3 2 4 3 Algoritma Analizi

Single Source Shortest Paths Problem Yaygin path finding problem (directed graflar icin) G = (V,E) Her bir arc bir negative olmayan bir label a sahip (cost fonksiyon) Bir vertex source olarak belirlenir Problem: Verilen source dan diger her bir vertex e olan en kisa yolun cost ini hesaplamak Algoritma Analizi

Dijkstra nin shortest path algorithm Procedure Dijkstra; # vertex 1 den diger vertexlere olan en kisa yolun cost ini # hesaplar Begin (1) S:={1} (2) for i:=2 to n do (3) D[i]:=C[1,i]; # initialize D (4) for i:= 1 to n-1 do begin (5) choose a vertex w in V-S such that D[w] is a minimum (6) add w to S; (7) for each vertex v in V-S do (8) D[v]:= min(D[v],D[w]+C[w,v]) end Algoritma Analizi

Dijkstra devam… G = (V,E) V = {1,2,3, ……,n} ve vertex 1 source C iki boyutlu bir dizi ve C[i,j] vertex i den vertex j ye gitmek icin maliyet (cost). Eger vertex i den vertex j ye bir arc yoksa C[i,j] = (herhangi bir maliyetten cok daha buyuk bir sayi) Her bir adimda D[i] vertex i ye olan en kisa yolun uzunlugunu gosterir Algoritma Analizi

Ornek 1 10 100 2 30 5 50 10 60 3 4 20 Iteration S W D[2] D[3] D[4] Initial {1} - 10 30 100 1 {1,2} 2 60 {1,2,4} 4 50 90 3 {1,2,4,3} {1,2,4,3,5} 5 1 10 100 2 30 5 50 10 60 3 4 20 Algoritma Analizi

Dijkstra’s Algorithm Greedy Algorithm Local olarak en iyi olan sey global olarak da en iyi dir. Dijkstra’s shortest path algorithm bir greedy algoritmadir. Algoritma Analizi

Running Time of Dijkstra’s Algorithm Eger adjacency matrix kullanirsak (7) ve (8) O(n) zaman alir ve n-1 kere execute edilir. Dolaysisiyle toplam zaman O(n2) olur Eger e n2 den oldukca kucukse, digraph i temsil icin adjacency list ve V-S kumesindeki vertices leri temsil etmek icin partially ordered tree kullanmak faydali olur. (7) ve (8), w nin adjacency list i taranarak ve priority queue deki mesafelerin guncellenmesiyle saglanir. Toplam olarak e tane guncelleme olur ve herbiri O(logn) zaman alir. Toplam zaman O(elogn) olur Algoritma Analizi

All-Pairs Shortest Paths Problem (APSP) Directed Graph G=(V,E) Her bir sirali cift vertices (v,w) icin vertex v den vertex w olan en kisa yolun mesafesini hesapla Dijkstra’s algoritmasi her bir vertex source kabul edilerek APSP problem cozulebilir (algoritma n kere cagrilir) Ikinci cozum Floyd’s Algorithm Algoritma Analizi

Floyd’s Algorithm procedure Floyd (var A: array[1..n, 1..n] of real, C: array[1..n, 1..n] of real) # Floyd computes shortest path matrix A given cost matrix C begin for i:=1 to n do for j:=1 to n do A[i,j] := C[i,j] for i:= 1 to n do A[i,i]:=0 for k:=1 to n do if A[i,k] + A[k,j] < A[i,j] then A[i,j]:=A[i,k] + A[k,j] end Algoritma Analizi

Ornek (Floyd’s Algorithm) 1 2 3 8 5 1 2 3 8 5 1 2 3 8 5 A0[i,j] A1[i,j] 1 2 3 8 5 1 2 3 7 5 8 A2[i,j] A3[i,j] Algoritma Analizi

Floyd’s Algorithm vs Dijkstra’s Algorithm Her ikisi de Adjacency Matrix kullanarak APSP problemini O(n3) zamanda cozer Eger e, graftaki edge sayisi, n2 den oldukca kucukse, Dijkstra nin algoritmasi O(nelogn) zamanda cozum getirebilir ( O(n3) den daha iyi oldugu umulur) Algoritma Analizi

En kisa yol uzerindeki vertex lerin belirlenmesi procedure shortest (var A: array[1..n, 1..n] of real, C: array[1..n, 1..n] of real) # C nxn boyutunda cost matrix, A nxn boyutunda en kisa yol matrix, # P nxn boyutunda shortest path lerdeki ara vertex leri tutar begin for i:=1 to n do for j:=1 to n do A[i,j] := C[i,j] P[i,j]:=0 for i:= 1 to n do A[i,i]:=0 for k:=1 to n do if A[i,k] + A[k,j] < A[i,j] then { A[i,j]:=A[i,k] + A[k,j] P[i,j]:=k } end Algoritma Analizi

Shortest Path Printing procedure path(i,j: integer) begin k:=P[i,j]; if k = 0 then return path(i,k) writeln(k) path(k,j) end Algoritma Analizi

Shortest path uzerindeki vertexler 1 2 3 8 5 1 2 3 Yukaridaki digraph icin P matrix i. Algoritma Analizi

Transitive Closure vertex i den vertex j ye bir yol var mi Cozum Floyd’un algoritmasini biraz degistirerek vertex i den vertex j ye bir yol var eger Numarasi k-1 den buyuk olmayan vertex lerden gecen vi den vj ye bir yol var veya Numarasi k-1 den buyuk olmayan vertexlerden gecen vi den vk ya bir yol ve numarasi k-1 den buyuk olmayan vertexlerden gecen vk dan vj ye bir yol var # A bir boolean matriks olmak uzere Ak[i,j]=Ak-1[i,j] || Ak-1[i,k] && Ak-1[k,j] Algoritma Analizi

Transitive Closure Warshall Algorithm procedure Warshall(var A: array[1..n,1..n] of boolean; C: array[1..n,1..n] of boolean) # Warshall makes A the transitive closure of C begin for i:=1 to n do for j:=1 to n do A[i,j]:=C[i,j] for k:=1 to n do for i:=1 to n do if A[i,j]=false then A[i,j]:=A[i,k] and A[k,j] end Algoritma Analizi

Bir Digraph in Center (merkezini) bulmak G=(V,E) Vertex v nin eccentricity si max { w den v ye olan minimum uzunluklu yolun uzunlugu) W in V G nin center i Minimum eccentricity e sahip vertex Algoritma Analizi

Ornek a b c d e 2 3 1 5 4 Center: vertex d vertex eccentricity a b 6 c 8 d 5 e 7 Center: vertex d Algoritma Analizi

a b c d e 2 3 1 5 4 G nin APSP cost matrix i ve nin vc ye uzakligi 1 3 5 7 2 4 6 8 ve nin vc ye uzakligi Graph G G nin center i vd Algoritma Analizi

Digraph larin Traversal i Digraph (directed graph) larla ilgili bir cok problemlerin cozumunde yonlu graf in vertex ve arc larini sistematik bir sekilde dolasmayi gerektirir Graph traversal Depth-First Search Bread-First Search Algoritma Analizi

Depth-First Search (DFS) B A E G D C Algoritma Analizi

Depth-First Search (DFS) B A E G D C Algoritma Analizi

Depth-First Search (DFS) B A E G D C Algoritma Analizi

Depth-First Search (DFS) B A E G D C Algoritma Analizi

Depth-First Search (DFS) G B D A C Algoritma Analizi

Depth First Search procedure dfs(v:vertex) w: vertex begin mark[v]:=visited for each vertex w on L[v] do if mark[w] = unvisited then dfs(w) end Algoritma Analizi

DFS nin Runnig Time Her bir vertex in adjacency list ine bir kez bakilir Vertex lerin adjacency list lerinin uzunluklari toplami e dir (graf in arc sayisi kadardir) Dolayisle DFS algorithm O(e) dir. Algoritma Analizi

Depth-First Spanning Forest B A E G D C Algoritma Analizi

Depth-First Spanning Forest B A E G D C Algoritma Analizi

Depth-First Spanning Forest B A E G D C Algoritma Analizi

Depth-First Spanning Forest B A E G D C Algoritma Analizi

Depth-First Spanning Forest DFST 1 DFST 2 F B A E G D C DFSP: Depth First Spanning Tree Algoritma Analizi

Depth-First Spanning Forest Tree 1 Tree 2 Edge Type Forward Backward Cross CA X DA DC FB GD GF F B A E G D C Tree edge: Foresteki her bir edge denir Algoritma Analizi

Depth-First Spanning Forest in Bulunmasi for v:=1 to n do mark[v]:=unvisited if mark[v]=unvisited then dfs(v) Algoritma Analizi

Directed Acyclic Graphs Directed Acyclic Grapg (DAC) Cycle a sahip olmayan directed graph Tree lerden daha genel fakat gelisiguzel graf lardan daha az genel Algoritma Analizi

A A B C D E A B C D E B C D E Tree Cycle sahip digraph DAG Algoritma Analizi

DAG DAG lar ortak subexpressionlara sahip aritmetik ifadelerin syntactic yapilarini gosterimde kullanilabilirler * + * * + c + + a b e f ((a+b)*c+((a+b)+e)*(e+f))*((a+b)*c) nin DAG ‘i Algoritma Analizi

Acyclic Testi Verilen bir directed graph G nin acyclic (bir cycle icerip icermediginin) testi DFS(depth first search) kullanilarak digrapin acyclic olup olmadigi karar verilebilir Eger DFS sirasinda bir back edge e rastlanilirsa graph in bir cycle a sahip oldugu anlasilir Algoritma Analizi

Her bir cycle bir back arc icerir v u Algoritma Analizi

Topological Sort Buyuk capli proje bir dizi alt projelere bolunur Bu alt projeler belli bir siraya gore tamamlanmali Ornegin alt proje C baslamasi A ve B nin tamamlanmasindan once olamaz DAG bu tip durumlari modellemek icin kullanilabilir Algoritma Analizi

Topological Sort C1 C3 C5 C2 C4 Topological Sort: DAG in vertices lerine linear ordering olacak sekilde sirala oyleki eger vertex i den vertex j ye bir arc varsa, linear ordering de i, j den once gelir. Yukaridaki DAG a gore C1,C2,C3,C4,C5 bir linear ordering dir. Algoritma Analizi

Topological Sort procedure topsort(v:vertex) # print vertices accessible from v in reverse topological order begin mark[v]:=visited for each vertex w on L[v] do if mark[w] = unvisited then topsort(w) writeln(v) end Algoritma Analizi

Strong Components Strongly connected component (SCC): Bir directed grafin SCC i, vertex lerden olusan maximal bir set oyleki bu sette bulunan herhangi iki farkli vertex arasinda yonlu bir yol var G = (V,E) bir digraf. V equivalance class lara bolunebilir Vi, 1<=i<=r, oyleki v ve w equivalent oyleki v den w ve w den v ye yollar var Gi=(Vi,Ei) lere strong components (strongly connected components) denir Strongly connected graph: Sadece bir tane strong componente sahip digraph Algoritma Analizi

Ornek d a b c a b d c digraph Digraph in strong componetleri Algoritma Analizi

ornek A F B C D G E A F B C D G E Digrah Strong Components ABDF EG C Condensation Graph (reduced graph) Algoritma Analizi

Strongly connected componentlerin bulunmasi # verilen bir digraph G icin SCC lerin bulunmasi 1. G ye depth-first search uygula ve vertex leri recursive call larin bitis sirasina gore numaralandir 2. G deki arc larin yonlerini ters cevirmek suretiyle yeni bir graph Gr bul. 3. Gr uzerinde 1. adimda elde edilen en yuksek numarali vertex den baslamak suretiyle depth-firstsearh uygula. Eger depth-first search butun vertex lere erisemezse , sonraki depth-first search i kalan vertex ler icerisinden en kucuk numarali vertex den baslat 4. Bulunan spanning foresteki her bir tree G nin bir strongly connected componentidir Algoritma Analizi

ornek a b c d 3 2 1 1. adim 4 d a b c digraph 4 a b 3 a 4 b 1 2 c d c Algoritma Analizi

Ornek Digraph G Digraph Gr Birinci SC nin bulunmasi F B C D G E E GAF BDC A D B G F C E Digraph G Digraph Gr A D A D B G B G F C E F C E Birinci SC nin bulunmasi 3 tane SC nin bulunmasi Algoritma Analizi