Graph
When we talk about graphs we make a fundamental distinction between directed and undirected graphs.
Also, when dealing with graphs we assume:
is always finite ( ) - We use sets
, rather than pairs
Directed Graph
A directed graph G is a pair
- V is vertex (node) set, which we assume is finite (
) - A vertex is represented by a circle
is edge (arch) set - An edge is a binary relation on V and is represented by an arrow
- Self-loops are allowed

At high level, a graph is a binary relation between a certain number of objects (vertices). Furthermore, a binary relation on a certain set A, is the sub-set of the cartesian product of that same set A.
This means the maximum number of edges can be found when
Undirected Graph
A directed graph G is a pair
- V is vertex (node) set, which we assume is finite (
) - E is edge (arch) set, which consists of unordered pairs of vertices
- An edge between
- It is like there is a symmetric relation between the vertices
and - If this was a directed graph, there must be one arrow that goes
and one
- It is like there is a symmetric relation between the vertices
- An edge is a set
where and - Self-loops are not allowed, this is why
- Self-loops are not allowed, this is why
- An edge between

Many definitions for directed and undirected graphs are the same, although certain terms have slightly different meanings in the two contexts
Adjacency - Vertices' POV
Two vertices u,v are adjacent if there is an edge that connects them.
- The vertex v is adjacent to vertex u.
Incidence - Edge's POV
For an edge, we would say that the edge (u,v) is incident from vertex u, and is incident to vertex v.
Implementations
In computer science, regardless of the type of graph used, the most common implementations to represent these data structures are:
- Adjacency List
- Best for sparse graphs
- Adjacency Matrix
- Best for tight/dense graphs
- Incidence Matrix
- Best for sparse graphs
