Category Archives: Sorting

Chocolate Distribution Problem

Given an array of n integers where each value represents number of chocolates in a packet. Each packet can have variable number of chocolates. There are m students, the task is to distribute chocolate packets such that : Each student gets one packet. The difference between the number of chocolates in packet with maximum chocolates… Read More »

Asymptotic Analysis and comparison of sorting algorithms

It is a well established fact that merge sort runs faster than insertion sort. Using asymptotic analysis we can prove that merge sort runs in O(nlogn) time and insertion sort takes O(n^2). It is obvious because merge sort uses a divide-and-conquer approach by recursively solving the problems where as insertion sort follows an incremental approach.… Read More »

Position of an element after stable sort

Given an array of integers which may contain duplicate elements, an element of this array is given to us, we need to tell the final position of this element in the array, if a stable sort algorithm is applied. Examples: Input : arr[] = [3, 4, 3, 5, 2, 3, 4, 3, 1, 5], index… Read More »