Network Representation Adjacency Matrices and Adjacency Lists
Network Representation Adjacency Matrices and Adjacency Lists
A 2D array where each cell indicates whether two A list of all the nodes, each with a list of its neighboring
nodes are connected. nodes.
Adjacency Matrices: Pros
and Cons
1 Pros 2 Cons
Constant-time lookups for Require N^2 space,
edge existence. where N is the number of
nodes.
3 Cons 4 Cons
Inefficient for sparse Difficult to iterate over a
graphs with many node's neighbors.
missing edges.
Adjacency Lists: Pros and
Cons
1 Pros 2 Pros
Require only O(|E|) space, Efficient for iterating over
where |E| is the number a node's neighbors.
of edges.
3 Cons 4 Cons
Require O(|E|) time to Can be more complex to
check if an edge exists. implement than
adjacency matrices.
Identifying Connected Components
Connected Components Importance
A connected component is a set of nodes where each Knowing the connected components is crucial for
node is reachable from every other node in the set. understanding the structure and connectivity of a
network.
Depth-First Search (DFS) Algorithm
Explore Deeply 1
DFS visits a node, then recursively explores all its
neighbors before backtracking.
2 Stack-Based
DFS uses a stack data structure to keep track of the
nodes to visit.
Connected Components 3
DFS can be used to identify the connected
components in a network.
Breadth-First Search (BFS) Algorithm
Explore Broadly 1
BFS visits a node, then explores all its neighbors
before moving on to the next level.
2 Queue-Based
BFS uses a queue data structure to keep track of the
nodes to visit.
Shortest Paths 3
BFS can be used to find the shortest paths between
nodes in a network.
Determining the Number
of Connected Regions
Key Steps Key Steps
1. Represent the network 2. Perform a DFS or BFS
using an adjacency matrix traversal to identify the
or adjacency list. connected components.