datastructure5
datastructure5
Graph types
Graph representation
Graph Traversals
GRAPH
A graph is an non linear abstract data
structure that is used to implement the
mathematical concept.
Graph is a collection of vertices (also called
B
A D V=A,B,C,D
C E=(a,b)(a,c)(b,d)(c,d))
GRAPH TERMINOLOGY
Vertex − Each node of the graph is represented as a vertex.
Edge − Edge represents a path between two vertices or a line
between two vertices
Adjacent Vertices:- Two node or vertices are adjacent if they
are connected to each other through an edge. Vertex v1 is said
to be adjacent to a vertex v2 if there is an edge(v1, v2) or (v2,
v1).
Path:- connected line between edges called path
Cycle:- A cycle is a path in which first and last vertices are
the same.
Loop: An edge of a graph which join a vertex to itself is called
loop or a self-loop.
Degree:- The number of edges incident on a vertex
determine its degree.
Weight:- If every edge in the graph is assigned some with
value, called weight
Tree:- If all nodes are connected and there are no cycles in
the graph is called tree
GRAPH TYPES
Finite Graphs
Infinite Graph
Simple Graph
Multi Graph
Null Graph
Complete Graph
Directed Graphs
Undirected Graph
Bipartite Graph
Connected Graph
Disconnected Graph
Sub Graph
Weighted Graph
Cyclic Graph
Finite Graphs: A graph is said to be finite if
it has finite number of vertices and finite
number of edges.
Infinite Graph: A graph is said to be infinite
if it has infinite number of vertices as well as
infinite number of edges
Simple Graph: A simple graph is a graph
which does not contains more than one edge
between the pair of vertices. A simple railway
tracks connecting different cities is an
example of simple graph.
Multi Graph: Any graph which contain some
parallel edges but doesn’t contain any self-
loop is called multi graph. For example A
Road Map.
Null Graph: A graph of order n and size zero
that is a graph which contain n number of
vertices but do not contain any edge.
Complete Graph: A simple graph with n
vertices is called a complete graph if the
degree of each vertex is n-1, that is, one
vertex is attach with n-1 edges. A complete
graph is also called Full Graph
Digraph Graph: A graph G = (V, E) with a
mapping f such that every edge maps onto
some ordered pair of vertices (Vi, Vj) is called
Digraph. It is also called Directed Graph.
Ordered pair (Vi, Vj) means an edge between
Vi and Vj with an arrow directed from Vi to Vj.
Here in the figure:
e1 = (V1, V2)
e2 = (V2, V3)
e4 = (V2, V4)
Undirected Graphs: An Undirected graph G
consists of a set of vertices, V and a set of
edge E. The edge set contains the unordered
pair of vertices. If (u, v)∈E then we say u and
v are connected by an edge where u and v
are vertices in the set V.
Example: Let V = {1, 2, 3, 4} and E = {(1,
Adjacency Matrix:
The sequential representation
Adjacency List
The linked representation
ADJACENCY MATRIX:
The adjacency matrix shows which nodes are
adjacent to one another.
An Adjacency Matrix is a 2D array of size V x V
connecting them.
In the case of a directed graph, if node j is
Directed graph
ADJACENCY LIST
One way is to have the graph maintain a list
of lists, in which the first list is a list of
indices corresponding to each node in the
graph.
Each of these refer to another list that stores
used in sociology.
Mathematics: In this, graphs are useful in
conservation efforts.
In circuit networks where points of connection are
drawn as vertices and component wires become the
edges of the graph.
In transport networks where stations are drawn as
vertices and routes become the edges of the graph.
In maps that draw cities/states/regions as vertices
and adjacency relations as edges.
In program flow analysis where procedures or
modules are treated as vertices and calls to these
procedures are drawn as edges of the graph.
Once we have a graph of a particular concept, they
can be easily used for finding shortest paths, project
planning, etc.
In flowcharts or control-flow graphs, the statements
and conditions in a program are represented as
nodes and the flow of control is represented by the
edges.