Python graph

Introduction

A graph in mathematics and computer science consists of “nodes” which may or may not be connected with one another. Connections between nodes are called edges. A graph can be directed (arrows) or undirected. The edges could represent distance or weight.

default graph (left), directed graph (right)

Python does not have a graph data type. To use graphs we can either use a module or implement it ourselves: