# Category Archives: 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
Given a graph and a source vertex src in the graph, find the shortest paths from src to all vertices in the given graph. The… Read More
We recommend reading the following two posts as a prerequisite for this post.  Greedy Algorithms | Set 7 (Dijkstra’s shortest path algorithm)  Graph and its… Read More
Given a graph and a source vertex in the graph, find the shortest paths from the source to all vertices in the given graph. Examples:… Read More
We recommend reading the following two posts as a prerequisite to this post. Greedy Algorithms | Set 5 (Prim’s Minimum Spanning Tree (MST))  Graph and… Read More
Introduction to Prim’s algorithm: We have discussed Kruskal’s algorithm for Minimum Spanning Tree. Like Kruskal’s algorithm, Prim’s algorithm is also a Greedy algorithm. This algorithm always starts… Read More
Graph is a data structure that consists of the following two components:  A finite set of vertices also called nodes. A finite set of ordered… Read More
A minimum spanning tree (MST) or minimum weight spanning tree for a weighted, connected, undirected graph is a spanning tree with a weight less than… Read More
In the previous post, we introduced union find algorithm and used it to detect cycles in a graph. We used the following union() and find()… Read More
A disjoint-set data structure is defined as a data structure that keeps track of a set of elements partitioned into a number of disjoint (non-overlapping)… Read More
Given a binary 2D matrix, find the number of islands. A group of connected 1s forms an island. For example, the below matrix contains 5… Read More
The Floyd Warshall Algorithm is for solving all pairs of shortest-path problems. The problem is to find the shortest distances between every pair of vertices… Read More
Hamiltonian cycle: The Hamiltonian cycle of undirected graph          G <= V , E> is the cycle containing each vertex in V.… Read More
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
Given a Directed Graph and two vertices in it, check whether there is a path from the first given vertex to second. Example:  Consider the following… Read More