Graph Algorithms - Washington State University
Transcript of Graph Algorithms - Washington State University
![Page 1: Graph Algorithms - Washington State University](https://reader031.fdocuments.net/reader031/viewer/2022020705/61fb8ff52e268c58cd5fa687/html5/thumbnails/1.jpg)
Graph AlgorithmsCptS 223
![Page 2: Graph Algorithms - Washington State University](https://reader031.fdocuments.net/reader031/viewer/2022020705/61fb8ff52e268c58cd5fa687/html5/thumbnails/2.jpg)
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](https://reader031.fdocuments.net/reader031/viewer/2022020705/61fb8ff52e268c58cd5fa687/html5/thumbnails/3.jpg)
Getting from here to there...
Vertices
A
B
C
D
E F
G
H
![Page 4: Graph Algorithms - Washington State University](https://reader031.fdocuments.net/reader031/viewer/2022020705/61fb8ff52e268c58cd5fa687/html5/thumbnails/4.jpg)
A
B
C
D
E F
G
H
Edges
Getting from here to there...
![Page 5: Graph Algorithms - Washington State University](https://reader031.fdocuments.net/reader031/viewer/2022020705/61fb8ff52e268c58cd5fa687/html5/thumbnails/5.jpg)
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](https://reader031.fdocuments.net/reader031/viewer/2022020705/61fb8ff52e268c58cd5fa687/html5/thumbnails/6.jpg)
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](https://reader031.fdocuments.net/reader031/viewer/2022020705/61fb8ff52e268c58cd5fa687/html5/thumbnails/7.jpg)
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](https://reader031.fdocuments.net/reader031/viewer/2022020705/61fb8ff52e268c58cd5fa687/html5/thumbnails/8.jpg)
Simple Graphs
G = (V,E)
(u, v) ∈ E
u
v
![Page 9: Graph Algorithms - Washington State University](https://reader031.fdocuments.net/reader031/viewer/2022020705/61fb8ff52e268c58cd5fa687/html5/thumbnails/9.jpg)
Directed Graphs
(u, v) ∈ E
u
v
(v, u) !∈ E
![Page 10: Graph Algorithms - Washington State University](https://reader031.fdocuments.net/reader031/viewer/2022020705/61fb8ff52e268c58cd5fa687/html5/thumbnails/10.jpg)
Weighted Graphs
5
7
10
48
6
3
5
![Page 11: Graph Algorithms - Washington State University](https://reader031.fdocuments.net/reader031/viewer/2022020705/61fb8ff52e268c58cd5fa687/html5/thumbnails/11.jpg)
Path Cycle
![Page 12: Graph Algorithms - Washington State University](https://reader031.fdocuments.net/reader031/viewer/2022020705/61fb8ff52e268c58cd5fa687/html5/thumbnails/12.jpg)
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](https://reader031.fdocuments.net/reader031/viewer/2022020705/61fb8ff52e268c58cd5fa687/html5/thumbnails/13.jpg)
Use Adjacency lists
forSparse Graphs
![Page 14: Graph Algorithms - Washington State University](https://reader031.fdocuments.net/reader031/viewer/2022020705/61fb8ff52e268c58cd5fa687/html5/thumbnails/14.jpg)
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](https://reader031.fdocuments.net/reader031/viewer/2022020705/61fb8ff52e268c58cd5fa687/html5/thumbnails/15.jpg)
Topological Sort
In degree = 3
Out degree = 1
![Page 16: Graph Algorithms - Washington State University](https://reader031.fdocuments.net/reader031/viewer/2022020705/61fb8ff52e268c58cd5fa687/html5/thumbnails/16.jpg)
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](https://reader031.fdocuments.net/reader031/viewer/2022020705/61fb8ff52e268c58cd5fa687/html5/thumbnails/17.jpg)
Topological Sort
A
B
C
D
E
F
G
H
A,B,D,C,E,F,G,H
O(|V | + |E|)