مرتضي صاحب الزماني 1 basic graph algorithms. مرتضي صاحب الزماني 2...

31
ي ن ما ز ل ا ب ح صا ي ض ت ر م1 Basic Graph Algorithms

Upload: annis-willis

Post on 04-Jan-2016

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

1

Basic Graph Algorithms

Page 2: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

2

Graph Data Structures

Adjacency Matrix

[©Bazargan]

Page 3: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

3

Graph Data Structures

Adjacency Matrix

[©Bazargan]

Page 4: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

4

Graph Data Structures

Adjacency List

[©Bazargan]

Page 5: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

5

Graph Data Structures

Adjacency List

[©Bazargan]

Page 6: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

6

Graph Search Algorithms

[©Bazargan]

Page 7: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

7

Graph Search Algorithms

Graph BFS DFS

[©Bazargan]

Page 8: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

8

Depth-First Search

چون همة گره ها و O (|V| + |E|)پيچيدگي زماني: يالها حداکثر يک بار پيموده مي شوند.

Page 9: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

9

Breadth-First Search

.O (|V| + |E|)پيچيدگي زماني:

باشروع از يک گره، همة گره هاي قابل •دسترسي را در يک صف قرار مي دهد و آنها

را مالقات مي کند.

اگر گرهي قبال5 مالقات شده است در صف •قرار نمي گيرد.

تکرار براي هر گره در صف.•

: صف به جاي پشته.DFSتفاوت با •

Page 10: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

10

Topological Search

(.DAG )بدون سيکلبراي گراف جهت دار •

ها هميشه قبل parent: يعني Topologicalترتيب •از اوالد مالقات مي شوند.

جستجو شود.BFSمي تواند به صورت •C A

B

DE

C-A-E-B-D

Page 11: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

11

Spanning Tree

G’ or E’ E

بسياري از مسائل گراف به صورت کلي •زيرند:

[©Bazargan]

Page 12: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

12

Minimum Spanning Tree (MST)

• Formal Definition

[©Bazargan]

Page 13: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

13

Minimum Spanning Tree

Page 14: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

14

Kruskal MST Algorithm

http://students.ceid.upatras.gr/~papagel/project/contents.htm

[©Bazargan]

Page 15: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

15

Kruskal MST Algorithm

•Kruskal’s algorithm is O(m log m) (m=|E|)

Page 16: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

17

Shortest Path

• Used in VLSI routing.

• Single-Pair Shortest Path (SPSP):

Page 17: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

18

Single-Pair Shortest Path

,u در يک گراف وزن دار، براي دو گره •v V،

( vو u )شامل P Vمجموعه گره هاي حداقل Pرا طوري انتخاب کنيد که

بدهد.v به u از Gهزينه را در

Page 18: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

19

Dijkstra Algorithm

کوتاهترين مسير از يک گره به همة گره هاي ديگر را پيدا مي کند.

O(n2)

Initialize D

Find min distance from u to each node (so far)

Find shortest path by backtracing

Page 19: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

20

All-Pairs Shortest Path

کوتاهترين مسير بين همة •زوج گره ها.

Page 20: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

21

Matching

،G = (V, E) در يک گراف بدون جهت •E’ E را طوري پيدا کنيد که براي همة

مجاور ’E يک يال از حداکثر vگره هاي v .باشد

G

C A

B

DE

F

H

• Maximum matching: matching ي باماکزيمم تعداد )وزن( يالها.

C A

B

DE

F

H

Page 21: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

22

Min-Cut

Page 22: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

23

Steiner Minimum Tree (SMT)

Page 23: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

24

Steiner Minimum Tree

8

Page 24: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

25

Steiner Minimum Tree

• When D = V, SMT = MST.• When |D| = 2, SMT = Single Pair Shortest Path

Problem.• The SMT problem is NP-Complete.

Page 25: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

26

Rectilinear Steiner Tree(RST)

A steiner tree whose edges are constrained to be vertical or horizontal.

Steiner point

Demand point

Page 26: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

27

Rectilinear Steiner Minimum Tree(RSMT)

• Similar to the SMT problem, except that the tree T is a minimum cost rectilinear Steiner tree.

• This problem is NP-Complete but we can get an approximated solution to this problem by making use of the MST.

Page 27: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

28

Underlying Grid Graph

Page 28: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

29

Approximate Solution to RSMT

• Construct a MST T.

• Obtain a RST T’ from T by connecting the vertices in T using vertical and horizontal edges.

MST

or

a better one

There can be many solutions.

Page 29: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

30

Different Steiner Trees

Page 30: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

31

Approximate Solution to RSMT

It is proved that:

WMST 1.5 WRSMT

RSMT ي که ازMST به دست مي آيد

RSMT)واقعي )بهينه

Page 31: مرتضي صاحب الزماني 1 Basic Graph Algorithms. مرتضي صاحب الزماني 2 Graph Data Structures Adjacency Matrix [©Bazargan]

مرتضي صاحب الزماني

37

يک مرجع الکترونيکي

Algorithms and Complexity, Wilf:

http://www.cis.upenn.edu/~wilf/AlgComp3.html