3. GRAPHS
• Graph is a non-linear datastructure and is a set of vertices and edges.
set of (V,E) pairs
V-Vertices,E-Edges
• Vertcies can be represented as circles also known as nodes.
• Edge is represented as the line which is connecting two nodes.
Ex:
Here A,B,C are vertices.
(A,B),(B,C),(A,C) are edges.
Graph is a closed figure.
4. GRAPH TERMINOLOGY
1. Node: The vertices represented as circle.
2. Edge: The connection between two nodes represented by a line.
3. Adjacent node: The node which connects their edges.
4. Degree of a node: The no. of edges corresponding to a particular
node.
Degree(A) =2,Degree(B)=2 ,Degree(C)=2
5. 5. Size of a graph : The total no. of edges in a graph .
The total no. of edges are 3 so the size of the graph is 3.
6. Path : The sequence of vertices from source to destination.
-> A to C
-> A-B-C
-> A-D-C
6. TYPES OF GRAPHS
1. Directed graph: The direction is specified on the edge.
2. Undirected graph: No direction is specified on the edge.
3. Weighted graph: Need to specify weight for the edge.
4. Unweighted graph: No need to specify weight for the edge.
5. Cyclic garph: Starting and ending point should be same
6. Acyclic graph: The graph doesn’t need to be a cycle.
Undirected Graph Directed Graph Weigted Graph Unweighted Graph Cyclic Graph Acyclic Graph
7. REPRESENTATION OF GRAPHS
• Graphs can be represented by,
• Adjacency matrix : In this representation, the graph can be represented by
using a matrix of size total number of vertices by total no.of vertices.A graph
with 4 vertices can be represented by 4×4 class.Both rows and columns
represents vertices.The matrix is either filled with 1 or 0. Here 1 represents
edge from row to column vertex and 0 represents there is no edge.
->Representation of undirected and directed graph.
8. 2. Adjacency list: In this representation, every vertex of graph contains
list of its adjacent vertices.
->Directed graph representation using linked list and array.
9. APPLICATIONS OF GRAPHS
1. Analysis of electrical circuit.
2. It is used in project planning.
3. It is widely used in mathematical applications.
4. It is used in computer network.
5. Finding shortest routes.