# Category Archives: Sorting

## Print n smallest elements from given array in their original order

We are given an array of m-elements, we need to find n smallest elements from the array but they must be in the same order… Read More »

## Alternate sorting of Linked list

Given a linked list containing n nodes. The problem is to rearrange the nodes of the list in such a way that the data in… Read More »

## Python | Sort a List according to the Length of the Elements

In this program, we need to accept a list and sort it based on the length of the elements present within. Examples: Input : list… Read More »

## Minimum De-arrangements present in array of AP (Arithmetic Progression)

Given an array of n-elements. Given array is a permutation of some Arithmetic Progression. Find the minimum number of De-arrangements present in that array so… Read More »

## No of pairs (a[j] >= a[i]) with k numbers in range (a[i], a[j]) that are divisible by x

Given an array and two numbers x and k. Find the number of different ordered pairs of indexes (i, j) such that a[j] >= a[i]… Read More »

## Maximum array from two given arrays keeping order same

Given two same sized arrays A[] and B[] (both arrays contain distinct elements individually but may have some common elements), task is to form a… Read More »

## stable_sort() in C++ STL

Like std::sort(), stable_sort also sorts an array. The syntax is also same. Output : Array after sorting using default sort is : 0 1 2… Read More »

## Number of visible boxes after putting one inside another

Given N boxes and their size in an array. You are allowed to keep a box inside another box only if the box in which… Read More »

## Sorting using trivial hash function

Sorting using trivial hash function. Examples: Input : 9 4 3 5 8 Output : 3 4 5 8 9 We have read about various… Read More »

## Sort an array with swapping only with a special element is allowed

Given an array of length n + 1, containing elements 1 through n and a space, Requires the use of a given swap (index i,… Read More »

## Find array with k number of merge sort calls

Given two numbers n and k, find an array containing values in [1, n] and requires exactly k calls of recursive merge sort function. Examples:… Read More »

## Elements to be added so that all elements of a range are present in array

Given an array of size N. Let A and B be the minimum and maximum in the array respectively. Task is to find how many… Read More »

## Counting cross lines in an array

Given an unsorted array of distinct elements. Task is to count number of cross lines formed in an array elements after sorting the array elements.… Read More »

## Minimum number of elements to add to make median equals x

A median in an array with the length of n is an element which occupies position number (n+1)/2 after we sort the elements in the… Read More »

## Quickselect Algorithm

Quickselect is a selection algorithm to find the k-th smallest element in an unordered list. It is related to the quick sort sorting algorithm. Examples:… Read More »