Professional Documents
Culture Documents
23T3
Directed
Graphs
Weighted
Graphs
COMP2521 23T3
Directed and Weighted Graphs
Kevin Luxa
cs2521@cse.unsw.edu.au
directed graphs
weighted graphs
COMP2521
23T3 Generalising Graphs
Directed
Graphs
Weighted
Graphs
COMP2521
23T3 Directed Graphs
Example
Directed
Graphs
Applications
Terminology
Representation
DAGs
Weighted
Graphs c g
b d e
f a
COMP2521
23T3 Directed Graphs
Common Domains
Directed
Graphs
Applications
Terminology
Representation
DAGs
Weighted
Graphs
COMP2521
23T3 Digraph Terminology (I)
Directed
Graphs
Applications
Terminology
Representation
DAGs
Weighted
Graphs
Weighted
Graphs
COMP2521
23T3 Digraph Terminology (III)
Directed
Graphs
Applications
Terminology
Representation
DAGs
COMP2521
23T3 Directed Graphs
Implementation: Adjacency Matrix
Directed
Graphs
Applications
Terminology
Representation
DAGs
1 1
Weighted
Graphs
2 4 2 4
0 3 0 3
0 1 1 1 0 0 1 1 1 0
1 0 1 0 0 0 0 1 0 0
1 1 0 1 1 0 0 0 1 1
1 0 1 0 1 0 0 0 0 0
0 0 1 1 0 0 0 1 1 0
COMP2521
23T3 Directed Graphs
Problems and Applications
Directed
Graphs
Applications
Terminology
Representation
DAGs
Weighted
Graphs
• Is there a directed path from s to t? (transitive closure)
• What is the shortest path from s to t? (shortest path search)
• Are all vertices mutually reachable? (strong connectivity)
Weighted
c d
Graphs
a b g
e f h k
j
i
Is it a tree? Is it a graph?
No: it’s a dag, a directed acyclic graph.
COMP2521
23T3 Directed Acyclic Graphs
Application: the Topological Sort
Directed
Graphs
Applications
Terminology
Representation
DAGs
COMP2521
23T3 Directed Acyclic Graphs
Application: the Topological Sort
Directed
Graphs
Applications
Terminology
Representation
DAGs
Weighted
Graphs
Mostly the same algorithms as for undirected graphs:
dfs and bfs should all Just Work
COMP2521
23T3
Directed
Graphs
Weighted
Graphs
Weighted Graphs
COMP2521
23T3 Weighted Graphs
Directed
Graphs
Weighted
Graphs Some applications require us to consider a cost or weight
assigned to a relation between two nodes.
COMP2521
23T3 Weighted Graphs
Directed
Graphs
Weighted
Example: Major airline routes in Australia
Graphs
COMP2521
23T3 Weighted Graphs
Implementation
Directed
Graphs
Weighted
Graphs
Adjacency matrix:
• store weight in each cell, not just true/false.
• need some “no edge exists” value: zero might be a valid weight.
Adjacency list
• add weight to each list node
Edge list:
• add weight to each edge
COMP2521
23T3 Weighted Graphs
Implementation: Adjacency Matrix
Directed
Graphs
Weighted
Graphs
1 1 0.5
0.1
2 4 2 4
0.4 0.10.9
0.2
0.5
0 3 0 3
0 1 1 1 0 − 0.2 0.4 0.5 −
1 0 1 0 0 0.2 − 0.5 − −
1 1 0 1 1 0.4 0.5 − 0.1 0.1
1 0 1 0 1 0.5 − 0.1 − 0.9
0 0 1 1 0 − − 0.1 0.9 −
Weighted
Graphs
COMP2521
23T3 Weighted Graphs
Implementation: Adjacency List
Directed
Graphs
Weighted
Graphs
Weighted
Graphs
COMP2521
23T3 Feedback
Directed
Graphs
Weighted
Graphs
https://forms.office.com/r/aPF09YHZ3X