Count the number of islands

Given a binary matrix where 0 represents water and 1 represents land, count the number of islands in it. A island is formed by connected one’s.   For example, consider below image.    Above image highlights water in blue and land in grey in a 10 x 10 matrix. There are total five islands present in the above …

Flood Fill Algorithm

Flood fill (also known as seed fill) is an algorithm that determines the area connected to a given node in a multi-dimensional array.

Find shortest safe route in a field with sensors present

Given a rectangular field with few sensors present on it, cross it by taking the shortest safe route without activating the sensors.   The rectangular field is given in the form of M x N matrix and we need to find the shortest path from any cell in first column to any cell in the …

Find all occurrences of given string in a character matrix

Given a M x N matrix of characters, find all occurrences of a given string in the matrix. We are allowed to search the string in all eight possible directions i.e. North, West, South, East, North-East, North-West, South-East, South-West. Note that there should not be any cycles in the output path.

Inversion count of an array

Given an array, find the number of inversions of it. If (i < j) and (A[i] > A[j]) then the pair (i, j) is called an inversion of an array A. We need to count all such pairs in the array.

Custom Sort | Sort array based on another array

Given two arrays, reorder elements of first array by order of elements defined by the second array. Elements which are not present in the second array but present in first array should be appended in the end sorted. Second array can contain some extra elements which are not part of first array.

Custom Sort | Sort elements by their frequency and Index

Given an array, sort its element by their frequency and index. i.e. – If two elements have the different frequencies, then the one which has more frequency should come first. – If two elements have the same frequencies, then the one which has less index should come first.

External Sorting (External merge sort)

External sorting is a term for a class of sorting algorithms that can handle massive amounts of data. External sorting is required when the data being sorted do not fit into the main memory of a computing device (usually RAM) and instead they must reside in the slower external memory (usually a hard drive).

Hybrid QuickSort

A Hybrid Algorithm is an algorithm that combines two or more other algorithms that solve the same problem, either choosing one (depending on the data), or switching between them over the course of the algorithm. This is generally done to combine desired features of each, so that the overall algorithm is better than the individual …