##
Union-Find Algorithm | Set 2 (Union By Rank and Path Compression)
October 28, 2012

In the previous post, we introduced union find algorithm and used it to detect cycle in a graph.

October 28, 2012

In the previous post, we introduced union find algorithm and used it to detect cycle in a 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.

October 17, 2012

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 islands Input : mat[][] = {{1, 1, 0, 0, 0}, {0, 1, 0, 0, 1}, {1, 0, 0, 1, 1}, {0, 0, 0, 0, 0}, {1, 0, 1, 0, 1}… Read More »

June 7, 2012

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 in a given edge weighted directed Graph.

May 4, 2012

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 such that there is an edge (in graph) from the last vertex to the first vertex of the Hamiltonian Path.

April 10, 2012

Given a Directed Graph and two vertices in it, check whether there is a path from the first given vertex to second.

April 3, 2012

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 one cycle, else return false.

March 20, 2012

Breadth First Traversal (or Search) for a graph is similar to Breadth First Traversal of a tree (See method 2 of this post).

March 15, 2012

Depth First Traversal (or Search) for a graph is similar to Depth First Traversal of a tree. The only catch here is, unlike trees, graphs may contain cycles, so we may come to the same node again. To avoid processing a node more than once, we use a boolean visited array.

March 29, 2011

Following two algorithms are generally taught for Minimum Spanning Tree (MST) problem.

March 25, 2011

Depth-first search (DFS) is an algorithm (or technique) for traversing a graph.