# Category Archives: Algorithm

## Sorting 2D Vector in C++ | Set 2 (In descending order by row and column)

We have discussed some of the cases of sorting 2D vector in below set 1. Sorting 2D Vector in C++ | Set 1 (By row… Read More »

## BogoSort or Permutation Sort

BogoSort also known as permutation sort, stupid sort, slow sort, shotgun sort or monkey sort is a particularly ineffective algorithm based on generate and test… Read More »

## Find frequency of each element in a limited range array in less than O(n) time

Given an sorted array of positive integers, count number of occurrences for each element in the array. Assume all elements in the array are less… Read More »

## Odd-Even Sort / Brick Sort

This is basically a variation of bubble-sort. This algorithm is divided into two phases- Odd and Even Phase. The algorithm runs until the array elements… Read More »

## Sorting Vector of Pairs in C++ | Set 2 (Sort in descending order by first and second)

We have discussed some of the cases of sorting vector of pairs in below set 1. Sorting Vector of Pairs in C++ | Set 1… Read More »

## Sorting Vector of Pairs in C++ | Set 1 (Sort by first and second)

What is Vector of Pairs? A pair is a container which stores two values mapped to each other, and a vector containing multiple number of… Read More »

## Gnome Sort

Gnome Sort also called Stupid sort is based on the concept of a Garden Gnome sorting his flower pots. A garden gnome sorts the flower… Read More »

## Sleep Sort – The King of Laziness / Sorting while Sleeping

In this algorithm we create different threads for each of the elements in the input array and then each thread sleeps for an amount of… Read More »

## Know Your Sorting Algorithm | Set 2 (Introsort- C++’s Sorting Weapon)

We have discussed sorting weapons used by different languages in previous article. In this article, C++’s Sorting Weapon, Introsort is discussed. What is Introsort? Simply… Read More »

## Know Your Sorting Algorithm | Set 1 (Sorting Weapons used by Programming Languages)

Ever wondered how sort() function we use in C++/Java or sorted() in Python work internally? Here is a list of all the inbuilt sorting algorithms… Read More »

## Cocktail Sort

Cocktail Sort is a variation of Bubble sort. The Bubble sort algorithm always traverses elements from left and moves the largest element to its correct… Read More »

## Find Maximum number possible by doing at-most K swaps

Given a positive integer, find maximum integer possible by doing at-most K swap operations on its digits. Examples: Input: M = 254, K = 1… Read More »

## No of Factors of n!

Given a positive integer n, find the no of factors in n! where n

## Find even occurring elements in an array of limited range

Given an array that contains odd number of occurrences for all numbers except for a few elements which are present even number of times. Find… Read More »

## Number of non-negative integral solutions of a + b + c = n

Given a number n, find number of ways we can add 3 non-negative integers so that their sum is n. Examples : Input : n… Read More »