You are on page 1of 4

Graph Theory: Basics

A graph is an abstract notation used to represent the connection between pairs of objects.
Graph is a data structure that consists of the following two components:
1. A finite set of vertices also called as nodes.
2. A finite set of ordered pair of the form (u, v) called as edge. The pair is ordered because (u, v) is not
same as (v, u) in case of a directed graph(di-graph). The pair of the form (u, v) indicates that there is
an edge from vertex u to vertex v. The edges may contain weight/value/cost.
A graph consists of
 Vertices − Interconnected objects in a graph are called vertices. Vertices are also known as nodes.
 Edges − Edges are the links that connect the vertices.
There are two types of graphs −
 Directed graph − In a directed graph, edges have direction, i.e., edges go from one vertex to
another.
 Undirected graph − In an undirected graph, edges have no direction.
Graphs are used to represent many real-life applications:
 Graphs are used to represent networks. The networks may include paths in a city or telephone
network or circuit network.
 Graphs are also used in social networks like linkedin, Facebook. For example, in Facebook,
each person is represented with a vertex (or node). Each node is a structure and contains
information like person id, name, gender and locale.
Graph Definitions
A graph G consists of two types of elements: vertices and edges. Each edge has two endpoints,
which belong to the vertex set. We say that the edge connects (or joins) these two vertices. The vertex
set of G is denoted V(G), or just V if there is no ambiguity. An edge between vertices u and v is written
as {u, v}. The edge set of G is denoted E(G), or just E if there is no ambiguity. The graph in this picture
has the vertex set V = {1, 2, 3, 4, 5, 6}. The edge set E = {{1, 2}, {1, 5}, {2, 3}, {2, 5}, {3, 4}, {4, 5},
{4, 6}}
Self Loop: A self-loop is an edge whose end points are a single vertex. Multiple edges are two or more
edges that join the same two vertices.

Multi Graph: A graph is called simple if it has no self-loops and no multiple edges, and a multi
graph if it does have multiple edges.

Degree: The degree of a vertex v is the number of edges that connect to v.


Path: Path in a graph G = (V, E) is a sequence of vertices v1, v2, …, vk, with the property that there are
edges between vi and vi+1. We say that the path goes from v1 to vk. The sequence 6, 4, 5, 1, 2 is a
path from 6 to 2 in the graph above. A path is simple if its vertices are all different.
Cycle: A cycle is a path v1, v2, …, vk for which k > 2, the first k - 1 vertices are all different and v1 = vk.
The sequence 4, 5, 2, 3, 4 is a cycle in the graph above.A graph is connected if for every pair of
vertices u and v, there is a path from u to v.If there is a path connecting u and v,
the distance between these vertices is defined as the minimal number of edges on a path
from u to v.
Connected Component: A connected component is a sub-graph of maximum size, in which every pair
of vertices are connected by a path. Here is a graph with three connected components.

Trees: A tree is a connected simple acyclic graph. A vertex with degree 1 in a tree is called a leaf.
Directed graphs:
A directed graph or digraph G = (V, E) consists of a vertex set V and an edge set of ordered
pairs E of elements in the vertex set.

Here is a simple acyclic digraph (often called a DAG, “directed acyclic graph”) with seven vertices and
eight edges.
Adjacency matrix:
An adjacency matrix is a |V|x|V|-matrix of integers,
representing a graph G = (V, E).
 The vertices are number from 1 to |V|.
 The number at position (i, j) indicates the number of edges from i to j.
Adjacency Matrix is a 2D array of size V x V where V is the number of vertices in a graph. Let the 2D array be adj[][], a slot
adj[i][j] = 1 indicates that there is an edge from vertex i to vertex j. Adjacency matrix for undirected graph is always
symmetric. Adjacency Matrix is also used to represent weighted graphs. If adj[i][j] = w, then there is an edge from vertex i
to vertex j with weight w.

A spanning tree whose sum of weight (or length) of all its edges is less than all other possible spanning
tree of graph G is known as a minimal spanning tree or minimum cost spanning tree. The following
figure shows a weighted connected graph.

Some possible spanning trees of the above graph are shown below:
Among all the above spanning trees, figure (g) is the minimum spanning tree.
The concept of minimum cost spanning tree is applied in travelling salesman
problem, designing electronic circuits, designing efficient networks and designing
efficient routing algorithms. To implement the minimum cost-spanning tree, the
following two methods are used:
 Prim’s Algorithm
 Kruskal’s Algorithm

You might also like