# Category Archives: Sorting

## Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest, ..

Given an array of integers, task is to print the array in the order – smallest number, Largest number, 2nd smallest number, 2nd largest number,… Read More »

## Smallest element in an array that is repeated exactly ‘k’ times.

Given an array of size n, the goal is to find out the smallest number that is repeated exactly ‘k’ times where k > 0?… Read More »

## Minimum number of distinct elements after removing m items

Given an array of items, an i-th index element denotes the item id’s and given a number m, the task is to remove m elements… Read More »

## Ways to sort list of dictionaries by values in Python – Using itemgetter

Previous article of this segment dealt with sorting list of dictionaries by values using lambda function. Ways to sort list of dictionaries by values in… Read More »

## Merging two unsorted arrays in sorted order

Write a SortedMerge() function that takes two lists, each of which is unsorted, and merges the two together into one new list which is in… Read More »

## Find first k natural numbers missing in given array

Given an array of size n and a number k, we need to print first k natural numbers that are not there in given array.… Read More »

## Sorting Array Elements By Frequency | Set 3 (Using STL)

Given an array of integers, sort the array according to frequency of elements. If frequencies of two elements are same, print them in increasing order.… Read More »

## Why quicksort is better than mergesort ?

This a common question asked in DS interviews that despite of better worst case performance of merge sort, quicksort is considered better than mergesort. There… Read More »

## Recursive selection sort for singly linked list | Swapping node links

Given a singly linked list containing n nodes. The problem is to sort the list using recursive selection sort technique. The approach should be such… Read More »

## Why is it faster to process sorted array than an unsorted array ?

Here is a C++ code that illustrates that sorting the data miraculously makes the code faster than the unsorted version. Let’s try out a sample… Read More »

## Sort the biotonic doubly linked list

Sort the given biotonic doubly linked list. A biotonic doubly linked list is a doubly linked list which is first increasing and then decreasing. A… Read More »