Skip to content

Category Archives: Graph

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 connects… Read More
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
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
  Given a boolean 2D matrix, find the number of islands. A group of connected 1s forms an island. For example, the below matrix contains… Read More
  The Floyd Warshall Algorithm is for solving the All Pairs Shortest Path problem. The problem is to find shortest distances between every pair of… Read More
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
Given an undirected graph and a number m, determine if the graph can be coloured with at most m colours 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
Given a directed graph, check whether the graph contains a cycle or not. Your function should return true if the given graph contains at least… Read More
  Breadth-First Traversal (or Search) for a graph is similar to Breadth-First Traversal of a tree (See method 2 of this post). The only catch… Read More
  Depth First Traversal (or Search) for a graph is similar to Depth First Traversal of a tree. The only catch here is, unlike trees,… Read More
Following two algorithms are generally taught for Minimum Spanning Tree (MST) problem. Prim’s algorithm Kruskal’s algorithmAttention reader! Don’t stop learning now. Get hold of all… Read More
  Depth-first search (DFS) is an algorithm (or technique) for traversing a graph.  Following are the problems that use DFS as a building block.  Attention… Read More
Minimum Spanning Tree (MST) problem: Given connected graph G with positive edge weights, find a min weight set of edges that connects all of the… Read More

Start Your Coding Journey Now!