# Category Archives: Graph

## Check whether a given graph is Bipartite or not

A Bipartite Graph is a graph whose vertices can be divided into two independent sets, U and V such that every edge (u, v) either… Read More »

## Transitive closure of a graph

Given a directed graph, find out if a vertex j is reachable from another vertex i for all vertex pairs (i, j) in the given… Read More »

## Bellman–Ford Algorithm | DP-23

Given a graph and a source vertex src in graph, find shortest paths from src to all vertices in the given graph. The graph may… Read More »

## Dijkstra’s Algorithm for Adjacency List Representation | Greedy Algo-8

We recommend reading the following two posts as a prerequisite of this post. 1. Greedy Algorithms | Set 7 (Dijkstra’s shortest path algorithm) 2. Graph and… Read More »

## Dijkstra’s shortest path algorithm | Greedy Algo-7

Given a graph and a source vertex in the graph, find shortest paths from source to all vertices in the given graph. Dijkstra’s algorithm is… Read More »

## Prim’s MST for Adjacency List Representation | Greedy Algo-6

We recommend to read following two posts as a prerequisite of this post. 1. Greedy Algorithms | Set 5 (Prim’s Minimum Spanning Tree (MST)) 2.… Read More »

## Prim’s Minimum Spanning Tree (MST) | Greedy Algo-5

We have discussed Kruskal’s algorithm for Minimum Spanning Tree. Like Kruskal’s algorithm, Prim’s algorithm is also a Greedy algorithm. It starts with an empty spanning tree. The… Read More »

## Graph and its representations

Graph is a data structure that consists of following two components: 1. A finite set of vertices also called as nodes. 2. A finite set… Read More »

## Kruskal’s Minimum Spanning Tree Algorithm | Greedy Algo-2

What is Minimum Spanning Tree? Given a connected and undirected graph, a spanning tree of that graph is a subgraph that is a tree and… Read More »

## Union-Find Algorithm | Set 2 (Union By Rank and Path Compression)

In the previous post, we introduced union find algorithm and used it to detect cycle in a graph. We used following union() and find() operations… Read More »

## Disjoint Set (Or Union-Find) | Set 1 (Detect Cycle in an Undirected Graph)

A disjoint-set data structure is a data structure that keeps track of a set of elements partitioned into a number of disjoint (non-overlapping) subsets. A… Read More »

## Find the number of islands | Set 1 (Using DFS)

Given a boolean 2D matrix, find the number of islands. A group of connected 1s forms an island. For example, the below matrix contains 5… Read More »

## Floyd Warshall Algorithm | DP-16

The Floyd Warshall Algorithm is for solving the All Pairs Shortest Path problem. The problem is to find shortest distances between every pair of vertices… Read More »

## Hamiltonian Cycle | Backtracking-6

Hamiltonian Path in an undirected graph is a path that visits each vertex exactly once. A Hamiltonian cycle (or Hamiltonian circuit) is a Hamiltonian Path… Read More »

## m Coloring Problem | Backtracking-5

Given an undirected graph and a number m, determine if the graph can be colored with at most m colors such that no two adjacent… Read More »