collection of nodes that have data and are connected to other nodes
graph is a data structure (V, E) that consists of:
collection of vertices V
collection of edges E, represented as ordered pairs of vertices (u,v)
// vertices and edges
0 --- 3
| \
| 2
| /
1
// Graph
V = {0, 1, 2, 3}
E = {(0,1), (0,2), (0,3), (1,2)}
G = {V, E}
Graph Terminology
Adjacency: vertex is said to be adjacent to another vertex if they are connected by an edge
Path: sequence of edges which allows going from vertex A to vertex B
Directed Graph: graph in which an edge (u,v) doesn't necessarily mean that there is also an edge (v,u); edges in this type of graph represented by arrows to show directionj
Graph Representation
1. Adjacency Matrix
2D array of V x V vertices, each row and column representing a vertex
if value of any element a[i][j] is 1, it represents that there is an edge connecting vertex i and vertex j