Sorting Algotithms

Sorting is the basic operation required in most of the programs. For this which is used in right manner, the algorithm should be efficient and optimized. We have various algorithms from low to high efficiency.

Selection Sort:
In place logic of selecting the minimum in each pass and putting it in its appropriate place.
References:
Mycodeschool channel-youtube.
http://www.youtube.com/playlist?list=PL2_aWCzGMAwKedT2KfDMB9YA5DgASZb3U


Merge Sort:Mergesort is a comparison-based algorithm that focuses on how to merge together two pre-sorted arrays such that the resulting array is also sorted.

Insertion Sort:
Insertion sort is a comparison-based algorithm that builds a final sorted array one element at a time. It iterates through an input array and removes one element per iteration, finds the place the element belongs in the array, and then places it there.
Bubble Sort:  
Bubble sort is a comparison​-based algorithm that compares each pair of elements in an array and swaps them if they are out of order until the entire array is sorted. For each element in the list, the algorithm compares every pair of elements.


QuickSort:
Quicksort is a comparison-based algorithm that uses divide-and-conquer to sort an array. The algorithm picks a pivot element, , and then rearranges the array into two subarrays , such that all elements are less than , and , such that all elements are greater than or equal to .
HeapSort:

Heapsort is a comparison-based algorithm that uses a binary heap data structure to sort elements. It divides its input into a sorted and an unsorted region, and it iteratively shrinks the unsorted region by extracting the largest element and moving that to the sorted region.

Counting Sort:
Counting sort is an integer sorting algorithm that assumes that each of the  input elements in a list has a key value ranging from  to , for some integer . For each element in the list, counting sort determines the number of elements that are less than it. Counting sort can use this information to place the element directly into the correct slot of the output array.





Choosing The Right Algorithm:

To choose a sorting algorithm for a particular problem, consider the running time, space complexity, and the expected format of the input list.
AlgorithmBest-caseWorst-caseAverage-caseSpace ComplexityStable?
Merge SortYes
Insertion SortYes
Bubble SortYes
Quicksort best,  avgUsually not*
HeapsortNo
Counting SortYes
*Most quicksort implementations are not stable, though stable implementations do exist.

References:  brilliant.org

Comments

Popular posts from this blog

Bitwise right shift operators in Java

Program to to Merge Two sorted Linked lists in Java