Implementing weighted graphs in Python

Harshit Sharma
1 min readApr 27, 2020

--

Weighted Graphs

A weighted graph is a graph in which each branch is given a numerical weight. Therefore it is a special type of labeled graph in which the labels are numbers (which are usually taken to be positive).

Weighted graph visual

Applications of Weighted Graphs

Maps with weights representing distances.
Water networks with weights representing water capacity of pipes.
Electrical circuits with weights representing resistance or maximum voltage or maximum current.
Computer or phone networks with weights representing length of wires between nodes.

One of the canonical applications for weighted graphs is finding the shortest path between two nodes. These algorithms are used in Google Maps for example.

Code

--

--