0% found this document useful (0 votes)
44 views31 pages

GRAPH

The document discusses graphs and their basic terminology, types, representations, traversals and applications. Graphs consist of vertices and edges and can be represented using adjacency matrices or lists. Common graph types include directed, undirected and bipartite graphs. Graph traversal algorithms include depth-first search and breadth-first search.

Uploaded by

Ruchita Maaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views31 pages

GRAPH

The document discusses graphs and their basic terminology, types, representations, traversals and applications. Graphs consist of vertices and edges and can be represented using adjacency matrices or lists. Common graph types include directed, undirected and bipartite graphs. Graph traversal algorithms include depth-first search and breadth-first search.

Uploaded by

Ruchita Maaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

Graphs

 A graph G consists of set of objects called


Vertices and Edges.
 a finite, nonempty set of vertices V(G)
 a finite, possible empty set of edges E(G)
 G(V,E) represents a graph
 E={e1,e2,e3,…..}
 V={v1,v2,v3,…..}
Basic Terminology
1. Vertex (Node): A node is a terminal point or an
intersection point of edges.
2. Edge (Link): An edge e is a link between two nodes.
The link (i,j) is of initial I and terminal j.
3. Directed and Undirected Edge: In a graph G(V,E) an
edge, which is directed from one end to another is
called “directed edge”, an edge which has no specific
direction is called an “undirected edge”.
Weighted Edge - A weighted egde is an edge with cost
on
4. Loop :An edge of a graph which joins a node to itself
is called a “loop”it.
5. Incidence: An edge is said to be incident on a vertex
if the vertex is one of the endpoints of that edge.
Degree: Total number of edges connected to a vertex is
said to be degree of that vertex.
6. Adjacent Vertices: If there exists at least one edge
between two vertices vi and vj in a graph G, then Vi &
Vj are called adjacent vertices.
7. Adjacent Edges: If two edges ei, ej have one end
vertex common in a graph G, then ei and ej are called
adjacent edges.
8. Parallel Edges: If two or more edges of a graph g have the
same end vertices then these edges are called parallel edges.
E1,e2,e3

e1

e2

v1 v2
9. Odd or Even Vertex: If thee3 degree of vertex in the graph is
even, the vertex is said to be even vertex otherwise odd vertex.
Even vertex: B,C,D,F
Odd Vertex: A,E
10. Isolated Vertex: A vertex of graph g, which is not the
end of any edge is called isolated vertex or in other words,
isolated vertices are vertices with zero degree.
11. Pendant Vertex: A vertex of degree one is called a
pendant vertex.
12. Path: way to get from an origin to destination by
traversing edges in graph.
13. Cycle : A chain where the initial and terminal nodes
are the same and that does not use the same link more
than once is a cycle.
14. Circuit: A path in where the initial and terminal nodes
correspond. It is a cycle where all the links are traveled in
the same direction
15. Degree: The number of edges incident on a vertex is
called the degree of that particular vertex.
Types of Graph
1. Simple Graph
• A graph with no loops and no parallel edges is
called a simple graph.
2. Null Graph
A graph having no edges is called a Null Graph.
3. Directed Graph
In a directed graph, each edge has a direction.
Non-Directed Graph
A non-directed graph contains edges but
the edges are not directed ones.
4. Multiple Graph:
A graph that contains some multiple
edges(parallel edges) Is called multiple graph.
Self loops are not allowed.
5. Regular graph:
A graph G is said to be regular, if all its vertices
have the same degree. In a graph, if the degree
of each vertex is ‘k’, then the graph is called a ‘k-
regular graph’.
6. Subgraph:
A graph whose vertices and edges are subsets of another
graph. Formal Definition: A graph G'=(V', E') is a subgraph
of another graph G=(V, E)
7. Complete Graph:
• A bipartite graph ‘G’, G = (V, E) with partition V =
{V1, V2} is said to be a complete bipartite graph if
every vertex in V1 is connected to every vertex of
V2.
• In general, a complete bipartite graph connects
each vertex from set V1 to each vertex from set V2.
9. Bipartite Graph
A simple graph G = (V, E) with vertex partition V = {V1, V2}
is called a bipartite graph if every edge of E joins a vertex
in V1 to a vertex in V2.
In general, a Bipartite graph has two sets of vertices, let
us say, V1 and V2, and if an edge is drawn, it should
connect any vertex in set V1 to any vertex in set V2.
Representation of Graph
1. Adjacency Matrix
2. Adjacency List
3. Adjacency Multi-List
4. Path Matrix or Reachability Matrix
1. Adjacency Matrix
In this representation, graph can be represented using a matrix of size
total number of vertices by total number of vertices. That means if a
graph with 4 vertices can be represented using a matrix of 4X4 class. In
this matrix, rows and columns both represents vertices. This matrix is
filled with either 1 or 0. Here, 1 represents there is an edge from row
vertex to column vertex and 0 represents there is no edge from row
vertex to column vertex. undirected graph representation...
Directed graph representation...
2. Adjacency List
In this representation, every vertex of graph
contains list of its adjacent vertices. Directed
graph representation implemented using linked
list...
This representation can also be implemented
using array as follows..
Graph Traversals
General Technique for graph traversing is given below:
1. Initially al the nodes of the graph are marked as ‘unreached’.
2. After selecting a start node from where the traversing of the graph
starts, mark ‘reached’.
3. The node marked as ‘reached’ is placed on the ‘ready list’.
4. Now, the node from the ‘the ready list’ is selected and processed.
5. The processed node is deleted, and the adjacent node to the deleted
node is marked as ‘reached’ only if they are marked as ‘un-reached’.
These ‘reached’ nodes are then added to the ‘ready list’.
6. The whole process continues until the ‘ready list’ becomes empty.

Graph Traversal Techniques:


7. DFS
8. BFS
DFS (Depth First Search)
DFS traversal of a graph, produces a spanning tree as final result. Spanning Tree
is a graph without any loops. We use Stack data structure with maximum size of
total number of vertices in the graph to implement DFS traversal of a graph.

We use the following steps to implement DFS traversal...


Step 1: Define a Stack of size total number of vertices in the graph.
Step 2: Select any vertex as starting point for traversal. Visit that vertex and push
it on to the Stack.
Step 3: Visit any one of the adjacent vertex of the verex which is at top of the
stack which is not visited and push it on to the stack.
Step 4: Repeat step 3 until there are no new vertex to be visit from the vertex on
top of the stack.
Step 5: When there is no new vertex to be visit then use back tracking and pop
one vertex from the stack.
Step 6: Repeat steps 3, 4 and 5 until stack becomes Empty.
Step 7: When stack becomes Empty, then produce final spanning tree by
removing unused edges from the graph
BFS (Breadth First Search)

BFS traversal of a graph, produces a spanning tree as final result.


Spanning Tree is a graph without any loops. We use Queue data
structure with maximum size of total number of vertices in the graph
to implement BFS traversal of a graph.

We use the following steps to implement BFS traversal...


Step 1: Define a Queue of size total number of vertices in the graph.
Step 2: Select any vertex as starting point for traversal. Visit that
vertex and insert it into the Queue.
Step 3: Visit all the adjacent vertices of the verex which is at front of
the Queue which is not visited and insert them into the Queue.
Step 4: When there is no new vertex to be visit from the vertex at
front of the Queue then delete that vertex from the Queue.
Step 5: Repeat step 3 and 4 until queue becomes empty.
Step 6: When queue becomes Empty, then produce final spanning
tree by removing unused edges from the graph
Application of Graphs
1. Model of www
2. Resource Allocation Graph
3. Coloring of Maps
4. Scene Graphs
1. Model of www

Site S3

Site S1

Site S4

Site S2
• The model of www can be represented by a
graph(directed) where in nodes denote the
documents, papers, articles, etc., and the
edges represent the outgoing hyperlinks.
• Site S1 has link to page on Site S4.
• The pages S4 refers to pages on S2 and S3
2. Resource Allocation Graph
• In order to detect and avoid deadlocks, the OS
maintains Resource Allocation Graph for
processes that are active in system.
3. Coloring of Maps
Map has to be colored in such a fashion that no
two adjacent countries or regions have the same
colour.
Node represent regions and edge between two
regions denote two regions are adjacent.
4. Scene Graphs
The contents of a visual scene are also managed
by using graph data structure.
Virtual Reality Modeling Language VRML
supports scene graph programming mode.

You might also like