0% found this document useful (0 votes)
9 views

Graphrepresentation

The document provides a comprehensive overview of graphs, defining key concepts such as vertices, edges, and various graph terminologies including cycles, paths, and degrees. It discusses different types of graphs, their representations, and specific characteristics like connectedness and regularity. Additionally, it explains methods for graph representation, including adjacency and incidence matrices, as well as linked representations like adjacency lists.

Uploaded by

VAISHNAVI KUMARI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Graphrepresentation

The document provides a comprehensive overview of graphs, defining key concepts such as vertices, edges, and various graph terminologies including cycles, paths, and degrees. It discusses different types of graphs, their representations, and specific characteristics like connectedness and regularity. Additionally, it explains methods for graph representation, including adjacency and incidence matrices, as well as linked representations like adjacency lists.

Uploaded by

VAISHNAVI KUMARI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

GRAPHS

Dr. Jyothi Pillai


Professor
Bhilai Institute of Technology
Durg(C.G.)
Graphs
 A data structure that consists of a set of nodes (vertices, points)
and a set of edges (links, arrows, arcs or lines).
 A graph G is defined as follows:
G=(V,E)
where V(G): a finite, nonempty set of vertices/nodes.
E(G): used to connect these vertices/nodes.
 The vertices could be internal graph elements or external items
represented by integer indices or references.
 The set of edges describes relationships among vertices/nodes.
Example
A Graph G(V, E) with 5 vertices and six edges is
shown in the following figure:-
V(G1)={A, B, C, D}
E(G1)={(A,B), (B,C), (C,E), (E,D), (D,B), (D,A))
Graph Terminologies:

Multiple Edges/Parallel Edges/Multi-edge :


• Two or more edges that are incident to the same
two vertices
• If two vertices are joined by two or more edges, then
edges are called as Multiple Edges.

• Example- Multiple edges are useful in the consideration


of electrical networks.
Graph Terminologies:
Self-Loop:
• Self-loop or buckle is an edge in the graph that starts from one
of the graph's vertices and ends on same vertex.
• Edge whose endpoints are a single vertex and is drawn from
vertex to itself.

G1
In G1, edge (V, V) forming a loop at vertexV.

In G2,two loops are formed at vertices a & b


G2

In G3, one loop is formed at vertex 1.


G3
Graph Terminologies:
Adjacency :
Adjacent/Neighbour Nodes:
• Connected to each other through an edge.
• Both vertices are endpoints of same edge.
• Example- In G1, vertex v1 has two adjacent vertices v2 and v3
.

Adjacent Edges:
• Two distinct edges that share an end vertex.
• Example- In G1, edges e1 and e2 share same end vertex v1 .

G1
Graph Terminologies:
Edge Cost:
• Value that an edge holds to travel to another vertex.
• Weight of an edge/Edge Weight is referred as "cost" of the edge.
• In applications, weight may be a measure of the length of a route,
the capacity of a line, the energy required to move between
locations along a route, etc.

Example- Edge Costs of a-b and b-h are 15 and 5 respectively.


Graph Terminologies:

Order: Number of vertices in the graph.

Size: Number of edges in the graph.


Graph Terminologies:
Path :
• A sequence of vertices such that there is an
edge from each vertex to its successor.
• A circuit is a path in which the terminal vertex
coincides with the initial vertex
Graph Terminologies:
Cycle :
• A path from a vertex to itself is called a cycle.
• A graph is called cyclic if it contains a cycle;
otherwise it is called acyclic
Graph Terminologies:
Degree (Directed Graphs):
• Number of edges incident on a node or number of
vertexes connected to it.
Graph Terminologies:
• Indegree: Number of edges directing inwards on a node
• Outdegree: Number of edges directing outwards from a
node
• Degree = Indegree + Outdegree
Graph Representation

The technique which is to be used in order to


store graph into the computer's memory.

Two ways to store Graph into the computer's


memory are:-
• Sequential Representation
• Linked Representation
Graph Representation

Graph representation can be done in the


following ways:
• Set Representation
• Sequential Representation
• Linked Representation
Graph Representation
Set Representation:
Set representation of a graph involves 2 sets:

• Set of verticesV={V1,V2,V3, V4}

• Set of edges E={{V1,V2},{V2,V3},{V3,V4},{V4,V1}}

This representation is efficient for memory but does


not allow parallel edges.
Graph Representation

Sequential Representation:
This representation of a graph can be
represented by means of matrices:
• Adjacency Matrix
• Incidence matrix
• Path matrix
Graph Representation

Sequential Representation:
1. Adjacency Matrix:
This matrix includes information about the
adjacent nodes.

aij = 1 if there is an edge from Vi to Vj otherwise 0

It is a matrix of order V×V.


Graph Representation
Sequential Representation:
1. Adjacency Matrix:
For given Undirected graph, an adjacency matrix is −
Graph Representation
Sequential Representation:
1. Adjacency Matrix:

For the given Directed graph, an adjacency matrix is −


Graph Representation
Sequential Representation:
1. Adjacency Matrix:

For given Undirected weighted graph, an adjacency matrix is −


Graph Representation
Sequential Representation:

2. Incidence Matrix:
This matrix includes information about the incidence of
edges on the nodes.

aij=1 if the jth edge Ej is incident


on ith vertex Vi otherwise 0.

It is a matrix of order V×E.


Graph Representation
Sequential Representation:
2. Incidence Matrix:

In incidence matrix of directed graph-

• 0 is used to represent row edge not connected to column


vertex.

• 1is used to represent row outgoing edge to column


vertex.

• -1 is used to represent row incoming edge to column


vertex.
Graph Representation
Sequential Representation:
2. Incidence Matrix:

Incidence Matrix of given directed graph-


Graph Representation
Sequential Representation:
3. Path Matrix:
This matrix includes information about the simple path
between 2 vertices.

Here, Pij = 1 if there is a path from Vi to Vj otherwise 0.

It is also called as reachability matrix of graph G.


Graph Representation
Linked Representation:
1. Adjacency List
This representation gives information about nodes to
which a specific node is connected i.e. adjacency lists.

This representation gives the adjacency lists of vertices


with the help of array and linked lists.

In the adjacency lists, the vertices which are connected


with the specific vertex are arranged in the form of lists
which is connected to that vertex.
Graph Representation
Linked Representation:
1. Adjacency List
Graph Representation
Linked Representation:
1. Adjacency List

Directed Graph Adjacency List


Graph Representation
Linked Representation:
2. Edge Lists

A simple but poor way to represent a graph is by


an edge list.
Assuming the graph has no nodes that are
disconnected (i.e no edges incident to the node),
list all edges as pairs of vertices.
Graph Representation
Linked Representation:

2. Edge Lists

• For Example:
G= (V,E) =( [V1, V2, V3, V4, V5, V6],
[(V1, V2),(V1, V3),(V2, V3),(V3,V4),
(V4, V1),(V4, V5),(V4, V6),(V5, V4)])
Types of Graphs

1. Null Graph 10. Complete Graph


2. Trivial Graph 11. Cycle Graph
3. Non-directed Graph 12. Cyclic Graph
4. Directed Graph 12. Acyclic Graph
5. Connected Graph 13. Simple Graph
6. Disconnected Graph 14. Multi Graph
7. Labeled Graph 15. Planar Graph
8. Regular Graph 16. Hamiltonian Graph
Null Graph
A graph G=(V,E) where E=0 is said as Null Graph/
Order Zero Graph/ Empty Graph
A graph with an empty edge set, having no edges
connecting any pair of vertices.
Null graph consists of only isolated vertices with a
vacant edge set and no connections between them.
Trivial Graph
A graph G=(V, E)is trivial/singleton/ single vertex
graph if it contains only a single vertex and no edge.

It is the smallest possible graph that can be created


with least number of vertices i.e. one vertex only.

Used as a starting point for building more complex


graphs.
Non-Directed Graph
A graph G=(V,E) is called a non-directed graph if all
edges present between any two nodes are non-
directed.
Undirected edge has no orientation (no arrow head).
Difficult to identify starting and ending nodes of edge.
Non-Directed Graph

There are 4 vertices A,B,C and D and 4 edges


between vertices which are not directed.

Edge between vertices A & B doesn't have any


direction, it cannot be determined whether the edge
starts from vertex A or vertex B.

Similarly, we can't determine the ending vertex of the


edge between A & B.
Directed Graph
A graph G=(V, E) which has every edge mapping
onto some ordered pair of vertices (Vi, Vj) is called a
Directed Graph/Digraph.
All edges of a digraph are directed.
Easy to determine from which node it is starting and
at which node it is ending.
Directed edge has an orientation (has an arrow
head).
Directed Graph

The graph is an example of a directed graph, where:


e1=(V1, V2)
e2 = (V2, V3)
e4= (V2, V4)
Connected Graph
A Graph G = (V, E) is connected if any pair of
vertices (Vi,Vj) of a graph is reachable from one
another .

There must be at least a single path between every


pair of vertices.
Connected Graph

Example- Starting from vertex B and traversing to


H, there are various paths.
One of the paths is - B-> C-> D-> F-> E-> H
Similarly, there are other paths for traversing the
graph from vertex B to vertex H.
Disconnected Graph
A Graph G = (V, E) is said to be disconnected, if any
pair of vertices do not have a path between them.
In a disconnected graph, there exists at least one pair
of vertices that doesn't have a path between them.
Disconnected Graph
Example -
To traverse from vertex A to vertex G; a single path
doesn't exist between both vertices.
Labeled Graph
A graph G= (V, E) is called a Labeled Graph /
Weighted Graph, if vertices and edges of a graph
are labeled with value, name, date or weight
representing the cost of traversing that edge.
Regular Graph

A graph G= (V, E) is called a regular graph, if all


graph nodes have same degree.

If all vertices in a graph are of degree 'k', then it


is called a "k-regular graph".

If all vertices of a graph are of degree 6, then it is


called a 6-regular graph.
Regular Graph
In graph G1, there are 3 vertices named vertex A, B
and D.
2 edges are associated with A, one from B and
another from D. Degree of vertex A is 2.
Similarly, Degree of B and D is 2.
G1 is called a 2-regular graph as degree of all 3
nodes is 2.

G1
Regular Graph
In G2, there are four vertices named vertex E, F, G
and F.
Degree of all 4 vertices of G2 is 2 as only two
edges are associated with all vertices of G2.
G2 is also a regular graph as all nodes have same
degree of 2.

G2
Complete Graph/ Full Graph
A simple graph G=(V, E) with “n” vertices is called a
Complete Graph, if the degree of each vertex is n-1,
i.e., one vertex is attached with n-1 edges.

A complete graph of ‘n’ vertices is represented as Kn.

In a complete graph, exactly one edge is present


between every pair of vertices i.e. each vertex is
connected to every other vertex.
Complete Graph/ Full Graph
Graph K4 has 4 nodes E, F, G & H.
F has 3 edges connected to other 3 remaining
vertices of K4.
3 remaining vertices, have 3 edges associated with
each one of them.
All vertices of K4 has a separate edge connected to
other vertices, hence it is a complete graph.
Cycle Graph

A graph G=(V, E) is called a cycle graph, if there


are n vertices, n> = 3 and edges form a cycle.

In a cycle graph, the degree of all vertices will be 2


and there will be at least one cycle.

Example: A bike-sharing graph where cycles


represent the routes that the bikes take.
Cycle Graph

G1 G2 G3

Three graphs G1,G2&G3 are cyclic graphs because


i. No.of nodes for all graphs >=3.
ii. Degree of all vertices of all graphs is exactly 2.
Cyclic Graph

A graph G=(V, E) is called cyclic if it contains at


least one cycle or we can say it has a minimum of
one cycle present.
Cyclic Graph
The graph G1 has two cycles present, thus making it
a cyclic graph.

G1

Graph G2 is a cyclic graph as it contains one cycle.

G2
Acyclic Graph
A graph is called an acyclic graph if there are no or
zero cycles present in the graph

An acyclic graph is the complete opposite of a cyclic


graph.

Example- Graph G1 is acyclic as no zero cycles in it


.

G1
Simple Graph
A simple graph is a graph that does not contain
more than one edge between the pair of vertices.
No self-loops and no parallel edges are present in
the simple graph.
Example- A simple railway track connecting
different cities is an example of a simple graph.
Simple Graph

G1

Graph G1 has 3 vertices and 3edges.

Graph G1 has no self-loops and no parallel edges;


therefore, it is called a simple graph.
Multi Graph
A graph G= (V, E) is said to be a multigraph if
parallel edges/multiple edges are present but no
self-loops.
If more than one edge present between two
vertices, then that pair of vertices is said to be
parallel edges.
For example a Road Map.
Multi Graph

G1

Graph G1 has 3 vertices and 3 edges .

No self-loops, but two edges connect between


vertex A and vertex E of the graph.
Planar Graph
A planar graph is a graph that can be drawn in a
plane such that no two edges of it cross each other.

G1

The graph G1 is a planar graph as it has no two


edges intersecting.
Hamiltonian Graph
Suppose a closed walk in the connected graph
that visits every vertex of the graph exactly once
without repeating the edges. Such a graph is
called a Hamiltonian graph, and the walk is
called a Hamiltonian path.

A Hamiltonian path that starts and ends at the


same vertex is called a Hamiltonian circuit.
Hamiltonian Graph
Graph G1 is a Hamilton graph as it consists of a
closed path ABCDEFA starting from vertex A
and traverses all other nodes without traversing
any nodes twice in the path of traversal.

G1
THANKYOU

You might also like