Graphs and Types of Graphs🔥
Tags: cpp, programming, tutorial, career
Published: 2022-05-25 06:02:23

`Hello Everyone👋. It is my first time blogging. I love to write about programming and development.

Hope you will like it✨

---

 
So Let's Start the Journey with the Topic: - **GRAPHS**
What is Graph and Why is it important to know it?🤔

The graph is one of the most important topics for those preparing for placements and coding interviews as most companies ask graph questions during the coding rounds.

Let's start with the definition of **Graphs** 

_Graphs are non-linear data structures consisting of a finite set of vertices (i.e. nodes) connected by a set of edges. 
An edge is a line which connects two vertices. It is defined by **G = (V,E)**_


![Graph](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4jf489mz4ai7whp44jdd.png) 


**Do you know different types of the graph in DSA ??** 🤔. 

- _If Yes, that's great. Continue to Revise the concept_ ✌️

- _If No, Let's Understand this_ 🔥

---

 

**Types of Graphs**

- **Finite Graph** - As the name suggests (Finite), it is a graph with a finite number of vertices and edges.


![Finite](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ljcnuid2c1vayn9iuuqw.png)

---


- **Infinite Graph** - It is a graph with infinite vertices and edges.


![Infinite](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5njhntublboxgqz2v2tw.png)

---

- **Trivial Graph** - A finite graph is a trivial graph if it has only one vertex. It does not have any edge.


![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1sszkcz8l8sym3lezpck.png)


---


- **Simple Graph** - It is the graph if there exists one and only one edge between any pair of vertices.

![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2aqs05ikfgcfz7p8py3c.png)
 

---


- **Multi Graph** - It is the graph which contains more than one edge or loop between any two vertices.

![multi](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/45ellseeqcbhd1fankpm.png)

---


- **Null Graph** - It is the case of a trivial graph having n isolated vertices but no connecting edge between them.

![null](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7bczzkufyd4izfe362fb.png)

---


- **Complete Graph** - It is the simple undirected graph in which every pair of distinct vertices is connected by a unique edge. It is also known as a full graph, and the degree of each vertex must be n-1. Every pair of vertices should be connected.

1. An undirected complete graph with n vertices will have n(n-1)/2 edges

2. A directed complete graph with n vertices will have n(n-1) edges 


![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a9tuytsvspvkihdxjv43.png)

---

 
- **Pseudo Graph** - It is the graph containing the self-loop along with other edges.

![Pseudo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7mwr2ijmb73j00lbvdqo.png)

---


- **Regular Graph** - It is a simple graph with each vertex having the same degree. Therefore,  every complete graph is a regular graph.


![Regular](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yp8dr7q40sx74h99boku.png)

---


- **Bipartite Graph** - A graph is called a bipartite graph if its vertices can be partitioned into two non-empty disjoint sets. In bipartite graphs, there would be no edge that connects vertices from the same set.

![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q9ht2oriz4tirg42ih30.png)

![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gidaofbpe31lsxpou5vl.png)

---


- **Labelled Graph** - The graph is labelled graph if the edges are labelled with the name, data or weight. It is also known as **weighted graph**


![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5z5uakdljn30miqdcdp3.png)

---


- **Digraph** - It is the directed graph in which vertices are ordered in a particular sequence. The edges are represented by arrows. The arrow shows its direction. _For example A->B means there is an edge from A to B, not vice versa._

![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r2c6nfsulfiid84il54h.png)
 

---


- **Subgraph** - It is a graph whose vertices and edges are subsets of another graph. 

_Two Types of Subgraphs_:-

1. Vertices Disjoint Subgraph:-  A subgraph with no common vertex.

2. Edge Disjoint Subgraph:-  A subgraph with no common edge.

![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9la28ucl13q8mdd1u303.png)
 
 

![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3hiwtetqp599wnfb0hrt.png)
 

---


- **Connected or Disconnected Graph** - The graph is called connected if there exists a path from one vertex of the graph to any other vertex of the graph. It has at least n-1 edges.

![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h1c593486dhoy4ymjr7f.png)
 


The graph is called disconnected if it is not connected.


![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/76ijxtr6i0vifny9ojqt.png)
 

---


- **Cyclic Graph** - A graph that has one or more cycles is called cyclic graph. It contains a path from at least one node back to itself.


![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yiunuzuft3bys7cbcose.png)
 

---



- **Vertex labelled** - It is the graph that holds data in its vertices. It can help to determine the edges data like (key, value) pair mapping.



![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yc88ax0qiv3eek7w54qv.png)

---


- **Directed Acyclic Graph** - The graph is called DAG if the edges are directed and don't contain a cycle. The edges are represented using an ordered pair of vertices.


![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y0c9veyovzlwbtdvplbv.png)

 

---



`HURRAY🥳. You have learnt all the types of graph 🙌.`

`Thanks for your patience and I hope you enjoy reading this blog.
Kindly share your feedback, it will motivate me to write more such blogs🙂.`






---