Graph
Graph is a data structure that consists of 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 directed graph (di-graph). The pair of form (u, v) indicates that
there is an edge from vertex u to vertex v. The edges may contain weight.
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. Following is an example undirected graph with 5
vertices.
(Exercise 1 - Exercise 5)
Code: