The graph is a set of vertices connected with the help of edges. A graph may be directed or undirected, and all the vertices are connected to each other in the graph. We can represent a graph using an array of vertices and a two-dimensional array for edges. Basic operations we can perform on graphs are adding a vertex, displaying vertex, adding edges, etc.
Graph : The formal definition of a graph is that a graph is a set of items or nodes connected by edges.
The graph is declared or represented using the most common two ways :
Pros :Easy to implement and takes less time to process, like it takes o(1) to remove an edge.
Cons :It takes much space even if there is less number of edges are there.
Pros : Saves the space.
Cons : Queries can be done at o(v).