A node, also called a vertex, is an entity in a graph. Edges connect nodes to represent relationships, routes, dependencies, or other interactions. Unlike elements in a linear structure such as an array or queue, nodes participate in a nonlinear network. section 3.1
Nodes can represent different entities and participate in several graph forms:
- In an undirected graph, nodes connect through bidirectional edges. section 3.1
- In a directed graph, nodes connect through directional edges representing flows, causal relations, or dependencies. section 3.1
- A multigraph can contain several parallel edges between the same nodes, while a hypergraph can connect more than two nodes with one hyperedge. section 3.1
- Weighted graphs attach values such as distance, travel time, capacity, or fuel consumption to edges between nodes. section 3.1 section 4.4
Routing network
For a route between Queen’s Park and the Bahen Centre, intersections and points of interest—including the origin and destination—become nodes. Road segments become weighted edges, with weights such as distance, travel time, fuel consumption, or number of turns. section 4.4
Listing 3.1 Creating an undirected graph using NetworkX
import networkx as nx import matplotlib.pyplot as plt graph = nx.Graph() nodes = list(range(5)) #1 graph.add_nodes_from(nodes) edges = [(0,1),(1,2), (1,3), (2,3),(3,4)] #2 graph.add_edges_from(edges) nx.draw_networkx(graph, font_color="white")
Create five numbered nodes with NetworkX, connect them through an edge list, and draw the resulting undirected graph. section 3.1


















