Given an array arr[] of N points. The task is to sort these points according to it’s distance from the origin. Examples: Input: arr[] = { {5,0}, {4,0}, {3,0}, {2,0}, {1,0} } Read more →
Sorting
47 postsGiven a sorted rotated array, the task is to find index of minimum element of the array. Following solution assumes that all elements are distinct. Examples: Input : arr[] = {5, 6, Read more →
There are many fundamental and advanced sorting algorithms. All sorting algorithms are problem-specific, which means they work well on some specific problem but do not work well for all the problems. All Read more →
Merge sort is a sorting technique based on the divide and conquer technique. Recursively: split the list in half, sort each half, then merge the sorted halves together. Algorithm : MergeSort(A, p, Read more →
Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. It examines all pairs of adjacent elements, swapping them when they Read more →
Insertion sort is a simple sorting algorithm that works similar to the way you sort playing cards in your hands. For the 2nd, 3rd, 4th, etc. element: slide backwards into proper relative Read more →
In Selection Sort algorithm, First, find the smallest element and swap it with the first. Sort the rest of the list the same way. Algorithm : for i in 0 .. n-2 Read more →