Graph- Introduction
A Graph is a data structure consisting of vertices and edges. the theory associated with graph is called graph theory.
It can be used to solve many problems such as Planning routes for goods or services delivery, finding the shortest path, finding number of colours needed to colour the regions of a map and so on.
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/value/cost.
Types of graph:
- Connected graph
- Directed graph
- Tree graph
- Weighted graph
- Acyclic graph and cyclic graph
- Planner graph and non-planner graph
- Multigraph graph
- Pseudograph graph
- Complete graph
- Bipartite graph
- Regular Graph
- Cube Graph and Peterson Graph
- Path Graphs and NULL garph
- Isomorphic Graphs, walk and trail-path
Connected Graph:
A graph is said to be connected if there is a path between connecting every pair of nodes or vertices.
A graph which is not connected can be divided into connected components call disjoint connected subgraphs.
Disconnected graph
Graphs can be connected and disconnected. This means that the graph is constructed out of two or more sub-graphs without a path between these components. You can think of a disconnected graph as for the roads of the UK and France, since they aren’t connected by land.
Another Example:
A graph G is connected if there is a path in G between any given pair of vertices, otherwise it is disconnected. Every disconnected graph can be split up into a number of connected subgraphs, called components.
Directed Graph:
A directed graph or diagraph is a graph in which all the edges are directed.
In a directed graph, we represent an edge from i to j as pair(i,j). The formal description of a directed graph G is (V,E) where V is the set of vertices and E is the set of edges.
A directed graph is shown in the following figure:
Undirected graph
As clear to its name,It is collection of vertices and edges that are connected together without any direction.
TREE INTRODUCTION
A graph is a called a tree if it is connected and contain no loop.
A tree may contain a special node called the root node of the tree. The exterior nodes of the tree are called leaves of the tree.
A graph with n odes has exactly n-1 edges.
we can say that graph A is as subgraph of graph B if the nodes of A are a subset of the nodes of B and the edges of A are the edges of B on the corresponding nodes.
Properties of tree:
- A tree has exactly one root
- A tree has no cycle
- Vertices with same parent are called sibling
- Vertex without children is called leaf
- Vertices that have children are called internal vertices.
- Degree of a tree is the maximum allowed degree of any node in the tree.
- Depth of a vertex in a tree is the length of the unique path from the root of the tree to the vertex.
- A tree with n vertices has n-1 edges.
- In a tree there is one path between every pair of vertices
- if a connected graph with n vertices has n-1 edges then it is tree.
- If a graph with no loops has n vertices and n-1 edges then it is tree.
Weighted Graph
A graph is said to be weighted graph if some real number is assigned on every edge of a graph.
the weight may be some value, any variable and so on.
UnWeighted Graph
An unweighted directed graph (ugraph) is represented as a list of (vertex-neighbours) pairs, where the pairs are in standard order (as produced by key sort
with unique keys) and the neighbours of each vertex are also in standard order (as produced by sort
), every neighbour appears as a vertex even if it has no neighbours itself, and no vertex is a neighbour to itself.
Pseudograph
Regular graph
In graph theory, a regular graph is a graph where each vertex has the same number of neighbours; i.e. every vertex has the same degree or valency. A regular directed graph must also satisfy the stronger condition that the indegree and outdegree of each vertex are equal to each other.