A graph is a way of encoding relationships between objects in a mathematically rigorous way. That relationship could be between people, ideas, objects, or anything else that have relationships between them. These items in the graph are called vertices (or nodes) and the connections between them are called edges.
The set of vertices in a graph is denoted by the capital letter V. The vertices are often denoted with subscripts v1,v2 etc, where each vi∈V.
The set of edges in a graph is denoted by the capital letter E. Since an edge represents the connection between a pair of vertices vi and vj, we often denote the edges as these pairings (v1,jvj), where a=b, since we don't allow edges from a vertex to itself. And since each edge is formed of a pair of elements from V, we can say that E⊂V×V (where V×V is the set of pairings of elements in V).
With all this in hand, we can say that a Graph G=(V,E) is a specific arrangement of vertices V and edges between those vertices E. Conceptually, this means a graph is a set of points (vertices) with a bunch of lines (edges) drawn between the points (vertices).
We will now define some useful terms for describing aspects of graphs.
- adjacent: v1∼v2: Two vertices v1,v2 are adjacent (written as v1∼v2) in graph G, if the graph has an edge between them. This can be denoted mathematically by saying (v1,v2)∈E.
- neighbors: The neighbors of a vertex v are all vertices adjacent to it. This is also described as the set vertices that v has edges to.
- degree: The degree of a vertex v is the number of neighbors of the v. This is also described as the number of vertices that v is adjacent to.
A path is a sequence of vertices v0,v1,…,vk such that vi∼vi+1 for all i and no vertex is visited twice. A cycle is like a path but with vk∼v0. Formally, a cycle is a sequence v0,…,vk such that v0,…,vk, v1,…,vk,v0, v2,…,vk,v0,v1, etc., all form paths. The length of a path is the number of edges (k), and the length of a cycle is also the number edges (k+1).
A graph is connected if for every two vertices there exists a path from one to the other. Otherwise, it's disconnected and thus consists of several connected components. The distance between any two vertices in a connected graph is the length of the shortest path from one to the other.
An orientation of a graph is an assignment of a direction to each vertex of a graph. A graph with an orientation is called a directed graph. They behave a lot differently from normal graphs: for example a normal graph can be connected but it can have an orientation in which it's disconnected.