...

/

Representing Weighted Graphs

Representing Weighted Graphs

Explore how weighted graphs can be implemented.

Let’s see how we can adapt the graph representations introduced in the previous lessons to weighted graphs. Throughout this lesson, we’ll use the following weighted graph as a running example:

g 0 0 1 1 0->1 5 1->0 3 2 2 1->2 7 3 3 1->3 4 2->0:se 11 2->3 4
An example weighted graph

Weighted adjacency matrix

To represent a weighted graph using its adjacency matrix, we can simply use a matrix of integers instead of booleans. The entry A[i,j]A[i,j] will be 00 when there is no edge from ii to ...