Data Structure: Graph: Basic Terminologies and Representations Graph:-Graph
Data Structure: Graph: Basic Terminologies and Representations Graph:-Graph
Graph:-
A graph is a data structure that stores connected data. In other words, a graph G (or g) is defined
as a set of vertices (V) and edges (E) that connects vertices. The examples of graph are a social media
network, computer network, Google Maps, etc.
Each graph consists of edges and vertices (also called nodes). Each vertex and edge have a
relation. Where vertex represents the data and edge represents the relation between them. Vertex
is denoted by a circle with a label on them. Edges are denoted by a line that connects nodes
(vertices).
Graph Terminology
Vertex: Vertices are the point that joints edges. It represents the data. It is also known as a node.
It is denoted by a circle and it must be labeled. To construct a graph there must be at least a node.
For example, house, bus stop, etc.
Edge: An edge is a line that connects two vertices. It represents the relation between the vertices.
Edges are denoted by a line. For example, a path to the bus stop from your house.
Weight: It is labeled to edge. For example, the distance between two cities is 100 km, then the
distance is called weight for the edge.
Path: The path is a way to reach a destination from the initial point in a sequence.
Types of Graph
• Weighted Graph: In a weighted graph, each edge contains some data (weight)
such as distance, weight, height, etc. It denoted as w(e). It is used to calculate the
cost of traversing from one vertex to another. The following figure represents a
weighted graph.
• Unweighted Graph: A graph in which edges are not associated with any value is
called an unweighted graph. The following figure represents an unweighted graph.
• Connected Graph: A graph is said to be connected if there exists at least one path
between every pair of vertices. Note that a graph with only a vertex is a connected
graph.
There are two types of connected graphs.
• Weekly Connected Graph: A graph in which nodes cannot be visited by a single path
is called a weekly connected graph.
• Multi Graph: A graph that has multiple edges connecting the same pair of nodes.
The following figure represents a multi-graph.
• Dense Graph: A graph in which the number of edges is close to the maximal number
of edges, the graph is called the dense graph. The following figure represents a dense
graph.
• Sparse Graph: A graph in which the number of edges is close to the minimal number
of edges, the graph is called the sparse graph. It can be a disconnected graph. The
following figure represents a sparse graph.