Graphs
Graphs
A graph is a non-linear kind of data structure made up of nodes or vertices and edges. The edges connect any two nodes
in the graph, and the nodes are also known as vertices.
• 1. Finite Graph
• The graph G=(V, E) is called a finite graph if the number of vertices
and edges in the graph is limited in number
2. Infinite Graph
• An undirected graph comprises a set of nodes and links connecting them. The
order of the two connected vertices is irrelevant and has no direction. You can
form an undirected graph with a finite number of vertices and edges.
13. Connected Graph
• If there is a path between one vertex of a graph data structure and any
other vertex, the graph is connected.
14. Disconnected Graph
• When there is no edge linking the vertices, you refer to the null graph
as a disconnected graph.
15. Cyclic Graph
• It's also known as a directed acyclic graph (DAG), and it's a graph with
directed edges but no cycle. It represents the edges using an ordered
pair of vertices since it directs the vertices and stores some data.
18. Subgraph
• The vertices and edges of a graph that are subsets of another graph are
known as a subgraph.
Representation of Graphs in Data Structures
• Graphs in data structures are used to represent the relationships between objects.
Every graph consists of a set of points known as vertices or nodes connected by
lines known as edges. The vertices in a network represent entities.
The most frequent graph representations are the two that follow:
•Adjacency matrix
•Adjacency list
Adjacency Matrix
Web pages are referred to as vertices on the World Wide Web. Suppose
there is a link from page A to page B that can represent an edge. This
application is an illustration of a directed graph.
Google Maps is another application that makes use of graphs. In the case of
Google Maps, each place is referred to as a node, and the roads that connect
them are referred to as edges.
• GPS systems and Google Maps use graphs to find the shortest path
from one destination to another.
• The Google Search algorithm uses graphs to determine the
relevance of search results.
• World Wide Web is the biggest graph. All the links and hyperlinks
are the nodes and their interconnection is the edges. This is why we
can open one webpage from the other.
•The nodes we represent in our graphs can be considered as the buildings, people,
group, landmarks or anything in general , whereas the edges are the paths
connecting them.
Just like in the below image, egdes are the roadways / path connecting the
nodes(like people, buildings, transports, etc).