Graph mechanics and types
There are multiple types of graphs, each with its unique attributes:
- Simple graph: A graph with no parallel edges or loops.
- Directed graph (DiGraph): A graph where each edge has a direction, indicating a one-way relationship.
- Undirected graph: A graph where edges don’t have a specific direction, suggesting a mutual relationship.
- Weighted graph: A graph where each edge carries a weight, often representing distances, costs, etc.
In this chapter, we will use the networkx
Python package to represent graphs. It can be downloaded from https://networkx.org/. Let’s try to create a simple graph using the networtx
package in Python. A “simple graph,” as alluded to in graph theory, is a graph that has no parallel edges or loops. To begin with, let’s try to create an empty graph, aGraph
, with no vertex or node:
import networkx as nx
graph = nx.Graph()
Let’s add a single vertex:
...