Before we start, if not already done, we need to install the networkx
library using the pip
tool. Execute the following code in its own cell:
!pip install networkx
Most of the algorithms provided by networkx
are directly callable from the main module. Therefore a user will only need the following import
statement:
import networkx as nx
As a starting point, let's review the different types of graphs supported by networkx
and the constructors that create empty graphs:
Graph
: An undirected graph with only one edge between vertices allowed. Self-loop edges are permitted. Constructor example:G = nx.Graph()
Digraph
: Subclass ofGraph
that implements a directed graph. Constructor example:G = nx.DiGraph()
MultiGraph
: Undirected graph that allows multiple edges between vertices. Constructor example:G = nx.MultiGraph()
MultiDiGraph
: Directed graph...