17
Graph Algorithms CptS 223

Graph Algorithms - Washington State University

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Graph Algorithms - Washington State University

Graph AlgorithmsCptS 223

Page 2: Graph Algorithms - Washington State University

Getting from here to there...

What data structure would you use ?

A

B

C

D

E F

G

H

How do you even think about the

problem ?

Lets strip away the the irrelevant details..

Page 3: Graph Algorithms - Washington State University

Getting from here to there...

Vertices

A

B

C

D

E F

G

H

Page 4: Graph Algorithms - Washington State University

A

B

C

D

E F

G

H

Edges

Getting from here to there...

Page 5: Graph Algorithms - Washington State University

5

7

10

48

6

3

5

A

B

C

D

E F

G

H

Weights

Getting from here to there...

Page 6: Graph Algorithms - Washington State University

looks a lot more simpler now...

5

7

10

48

6

3

5

A

B

C

D

E F

G

H

Getting from here to there...

Page 7: Graph Algorithms - Washington State University

Graphs

• Are a tool for modeling real world problems.

• Allow us to abstract details and focus on the problem.

• We can represent our domain as graphs apply algorithms to solve our problem.

Page 8: Graph Algorithms - Washington State University

Simple Graphs

G = (V,E)

(u, v) ∈ E

u

v

Page 9: Graph Algorithms - Washington State University

Directed Graphs

(u, v) ∈ E

u

v

(v, u) !∈ E

Page 10: Graph Algorithms - Washington State University

Weighted Graphs

5

7

10

48

6

3

5

Page 11: Graph Algorithms - Washington State University

Path Cycle

Page 12: Graph Algorithms - Washington State University

Representation of graphs

A

B

C

A

B

C

A

B

C

B A

C

0 1 1

1 0 1

1 1 0

A

B

C

A B C

Adjacency Matrix Adjacency List

|V 2| |V | + |E|

Page 13: Graph Algorithms - Washington State University

Use Adjacency lists

forSparse Graphs

Page 14: Graph Algorithms - Washington State University

Topological Sort

A

B

C

D

E

F

G

H

A,B,D,C,E,F,G,H

A

C

B

No Cycles

Page 15: Graph Algorithms - Washington State University

Topological Sort

In degree = 3

Out degree = 1

Page 16: Graph Algorithms - Washington State University

Topological Sort

A

B

C

D

E

F

G

H

A,B,D,C,E,F,G,HO(|V |2)

Page 17: Graph Algorithms - Washington State University

Topological Sort

A

B

C

D

E

F

G

H

A,B,D,C,E,F,G,H

O(|V | + |E|)