# Category Archives: Sorting

## 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 »

## Job Sequencing Problem – Loss Minimization

We are given N jobs numbered 1 to N. For each activity, let Ti denotes the number of days required to complete the job. For… Read More »

## Program to sort string in descending order

Given a string, sort it in descending order. Examples: Input : alkasingh Output : snlkihgaa Input : nupursingh Output : uusrpnnihg Input : geeksforgeeks Output… Read More »

## Minimum cost to sort a matrix of numbers from 0 to n^2 – 1

Given an n x n matrix containing all the numbers in the range 0 to n2-1. The problem is to calculate the total energy required… Read More »

## Rearrange positive and negative numbers using inbuilt sort function

Given an array of positive and negative numbers, arrange them such that all negative integers appear before all the positive integers in the array without… Read More »

## Median after K additional integers

Given an array of n integers. We are allowed to add k additional integer in the array and then find the median of the resultant… Read More »

## Sorting an array according to another array using pair in STL

We are given two arrays. We need to sort one array according to another. Examples: Input : 2 1 5 4 9 3 6 7… Read More »

## Maximize the sum of arr[i]*i

Given an array of N integers. You are allowed to rearrange the element of the array. The task is to find the maximum value of… Read More »

## Pairs with Difference less than K

Given an array of n integers, We need to find all pairs with difference less than k Examples: Input : a[] = {1, 10, 4,… Read More »

## Sort a Rotated Sorted Array

You are given a rotated sorted array and your aim is to restore its original sort in place. Expected to use O(1) extra space and… Read More »

## Circle Sort

Circle sort algorithm can be visualized by drawing concentric circles on an array of integers. The elements of the array lying on the same circle… Read More »

## Stable Selection Sort

A sorting algorithm is said to be stable if two objects with equal or same keys appear in the same order in sorted output as… Read More »

## Minimum product pair an array of positive Integers

Given an array of positive integers. We are required to write a program to print the minimum product of any two numbers of the given… Read More »

## Sort string of characters

Given a string of lowercase characters from ‘a’ – ‘z’. We need to write a program to print the characters of this string in sorted… Read More »