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.

Slides:



Advertisements
Similar presentations
You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
Advertisements

Advanced Piloting Cruise Plot.
Chapter 1 The Study of Body Function Image PowerPoint
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
By D. Fisher Geometric Transformations. Reflection, Rotation, or Translation 1.
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
My Alphabet Book abcdefghijklm nopqrstuvwxyz.
0 - 0.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Addition Facts
Year 6 mental test 5 second questions
ZMQS ZMQS
Directed Acyclic Graph
ABC Technology Project
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.
1 Undirected Breadth First Search F A BCG DE H 2 F A BCG DE H Queue: A get Undiscovered Fringe Finished Active 0 distance from A visit(A)
VOORBLAD.
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
1 Directed Depth First Search Adjacency Lists A: F G B: A H C: A D D: C F E: C D G F: E: G: : H: B: I: H: F A B C G D E H I.
Squares and Square Root WALK. Solve each problem REVIEW:
© 2012 National Heart Foundation of Australia. Slide 2.
Lets play bingo!!. Calculate: MEAN Calculate: MEDIAN
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Chapter 5 Test Review Sections 5-1 through 5-4.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
Addition 1’s to 20.
25 seconds left…...
Januar MDMDFSSMDMDFSSS
Week 1.
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
CS203 Lecture 15.
1 Unit 1 Kinematics Chapter 1 Day
PSSA Preparation.
How Cells Obtain Energy from Food
Traktor- og motorlære Kapitel 1 1 Kopiering forbudt.
Bioinformatics Programming 1 EE, NCKU Tien-Hao Chang (Darby Chang)
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.
Elementary Graph Algorithms Depth-first search.Topological Sort. Strongly connected components. Chapter 22 CLRS.
CS 473Lecture 141 CS473-Algorithms I Lecture 15 Graph Searching: Depth-First Search and Topological Sort.
Graph Traversals. For solving most problems on graphs –Need to systematically visit all the vertices and edges of a graph Two major traversals –Breadth-First.
CS 473Lecture 141 CS473-Algorithms I Lecture 14-A Graph Searching: Breadth-First Search.
Graphs Breadth First Search & Depth First Search by Shailendra Upadhye.
1 Undirected Breadth First Search F A BCG DE H Source:
Breadth First Search. Two standard ways to represent a graph –Adjacency lists, –Adjacency Matrix Applicable to directed and undirected graphs. Adjacency.
Sept Elementary Graph Algorithms Graph representation Graph traversal -Breadth-first search -Depth-first search Parenthesis theorem.
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.
1 Chapter 22 Elementary Graph Algorithms. 2 Introduction G=(V, E) –V = vertex set –E = edge set Graph representation –Adjacency list –Adjacency matrix.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 20.
Graphs & Paths Presentation : Part II. Graph representation Given graph G = (V, E). May be either directed or undirected. Two common ways to represent.
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.
G RAPH A LGORITHMS Dr. Tanzima Hashem Assistant Professor CSE, BUET.
Elementary Graph Algorithms
Finding Shortest Paths
Advanced Algorithms Analysis and Design
Breadth First Search 11/21/ s
Graph Representation (23.1/22.1)
Breadth First Search s
Data structure for graph algorithms: Adjacent list, Adjacent matrix
Breadth First Search s
Elementary Graph Algorithms
Presentation transcript:

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. Amac, grafta s den diger vertex lere olan en kisa yollari bulmak

2 Breadth-First-Search (BFS) Verilen: – G = (V, E) –Belli bir source vertex Sistematik olarak s den erisilebilinen her vertexi bulmak icin G nin edge lerini inceler –S den erisilebilen vertex lerin s ye olan en kisa yollarini hesaplar –Root u s olan ve butun erisilebilen vertex leri iceren breadth-first-tree uretir

3 Breadth-First-Search (BFS) BFS colors each vertex: white -- kesfedilmemis (undiscovered) gray -- kesfedilmis fakat “hala bitirilmemis” black -- bitisik tum vertex leri kesfedilmis

4 BFS for Shortest Paths Finished Discovered Undiscovered S 1 1 1

5 BFS for Shortest Paths Finished Discovered Undiscovered S S

6 BFS for Shortest Paths Finished Discovered Undiscovered S S S

7 BFS(G,s) 1.for each vertex u in (V[G] \ {s}) 2do color[u]  white 3d[u]   4  [u]  nil 5color[s]  gray 6d[s]  0 7  [s]  nil 8Q   9enqueue(Q,s) 10while Q   11do u  dequeue(Q) 12for each v in Adj[u] 13do if color[v] = white 14then color[v]  gray 15d[v]  d[u]  [v]  u 17enqueue(Q,v) 18color[u]  black white: undiscovered gray: discovered black: finished Q: a queue of discovered vertices color[v]: color of v d[v]: distance from s to v  [v]: predecessor of v

8 Operations of BFS on a Graph

9

10 Operations of BFS on a Graph

11 Operations of BFS on a Graph

12 Operations of BFS on a Graph

13 Operations of BFS on a Graph

14 Operations of BFS on a Graph

15 Operations of BFS on a Graph

16 Operations of BFS on a Graph

17 Breadth-First Tree Graf G = (V, E) ve kaynak vertex s icin, G nin predecessor subgraph i G  = (V , E  ) – V  ={v  V :  [v]  NIL} – E  ={(  [v],v)  E : v  V  - {s}} G  nin subgraph i breadth-first tree dir eger – V  s den erisilebilinen vertex lerden (vertices) olusuyorsa – Her v  V  icin, G  de s den v ye tek bir yolsa (ayni zamanda bu yol en kisa yolsa) E  deki edge ler tree edges olarak adlandirilir. |E  | = |V  | - 1

18 Breadth-First Tree Verilen bir graf icin bir cok BFS tree bulunabilir. –Search in hangi vertex den basladigina ve kuyruga vertex ler hangi sirada yerlestirildigine bagli olarak BFS tree nin edge lerine tree edges G nin geri kalan edge lerine de cross edges denir.

19 Analysis of BFS Initialization O(V). Traversal Loop –Her bir vertex en fazla bir kez kuyruga itilir ve kuyruktan cekilir, ve her bir islem O(1) zaman alir. Dolayisiyle toplam zaman O(V). –Her bir vertex in adjacency list en fazla bir kez taranir. Adjacency liste lerin boylarinin toplami  (E). BFS nin calisma zamani O(V+E).

20 Shortest Paths Shortest-Path distance  (s, v) s den v ye minimum sayida edge sahip yolun uzunlugu, eger boyle bir yol yoksa 

21 Depth-First-Search (DFS) En son kesfedilen vertex v den itibaren edge leri incele Mumkun oldugunca derinlige in “Search as deep as possible first”

22 Depth-First Trees Boyama teknigi BFS dekine benzer. DFS nin predecessor subgraph i G  = (V, E  ), burada E  ={(  [v],v) : v  V ve  [v]  NIL}. G  nin predecessor subgraph i bir kac depth-first trees iceren bir depth-first forest olusturur. E  deki edge ler tree edges olarak adlandirilir. Her bir vertex u 2 timestamps e sahip: d[u] u ilk olarak discover edildigi zamani kaydeder (grayed) ve f[u] search in bitis zamanini (blackens) kaydeder. Her bir vertex u, d[u] < f[u].

23 DFS(G) 1. for each vertex u  V[G] 2. do color[u]  WHITE 3.  [u]  NIL 4. time  0 5. for each vertex u  V[G] 6. do if color[v] = WHITE 7. then DFS-Visit( v )

24 DFS-Visit(u) 1. color[u]  GRAY  White vertex u discover edildi 2. d[u]  ++time 3. for each vertex v  Adj[u] 4. do if color[v] = WHITE 5. then  [v]  u 6. DFS-Visit( v ) 7. color[u]  BLACK  Blacken u ; it is finished. 8. f[u]  time++

25 Operations of DFS

26 Analysis of DFS 1-2 & 5-7 satirlarindaki loop lar  (V) zaman alir (DFS-Visit i saymazsak). DFS-visit her bir white vertex v  V ilk olarak gray e boyandiginda bir kez cagrilir. DFS-Visit deki 3-6 line lari |Adj[v]| kadar execute edilir. DFS-Visit in toplam calisma suresi  v  V |Adj[v]| =  (E) DFS nin toplam calisma suresi  (V+E).