A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Types of Sorting

Bubble Sort
Bubble Sort

Bubble sort has a worst-case and average complexity of O(n2), where n is the number of items sorted. Unlike the other sorting algorithms, bubble sort detects whether the sorted list is efficiently built into the algorithm. Bubble sort performance over an already sorted list is O(n).

Bubblesort
Bubblesort

Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order.

Comparable Elements
Comparable Elements

All elements in the list must implement the Comparable interface. Furthermore, all elements in the list must be mutually comparable (that is, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the list).

image: cs.cmu.edu
Heapsort
Heapsort

A sorting algorithm that works by first organizing the data to be sorted into a special type of binary tree called a heap. The heap itself has, by definition, the largest value at the top of the tree, so the heap sort algorithm must also reverse the order.

source: webopedia.com
image: odicis.org
Heapsort Worst Case: O(NlogN)
Heapsort Worst Case: O(NlogN)

So given an input of lets say 10 strings, what way can we input these so we get the best or worst case for these two given sorts? Heap sort: best case - nlogn worst case - nlogn Quick sort: best ...

Insertion Sort
Insertion Sort

Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. At each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there. It repeats until no input elements remain.

Insertion Sort Algorithm
Insertion Sort Algorithm

Hence the name, insertion sort. The array is searched sequentially and unsorted items are moved and inserted into the sorted sub-list (in the same array). This algorithm is not suitable for large data sets as its average and worst case complexity are of Ο(n 2), where n is the number of items.

Merge Sort
Merge Sort

Merge sort is a sorting technique based on divide and conquer technique. With worst-case time complexity being Ο(n log n), it is one of the most respected algorithms. Merge sort first divides the array into equal halves and then combines them in a sorted manner.

Mergesort Code Methods: Mergesort (2), Merge
Mergesort Code Methods: Mergesort (2), Merge

Read and learn for free about the following article: Overview of merge sort

Quicksort
Quicksort

Like merge sort, quicksort uses divide-and-conquer, and so it's a recursive algorithm. The way that quicksort uses divide-and-conquer is a little different from how merge sort does. In merge sort, the divide step does hardly anything, and all the real work happens in the combine step.

Quicksort Code Methods: Quicksort (2), Median3
Quicksort Code Methods: Quicksort (2), Median3

Join over 2 million developers in solving code challenges on HackerRank, ... your code. Instead of creating number of methods, ... //Quicksort 2 - Sorting #include ...

image: algolist.net
Selection Sort Array to be Sorted: A
Selection Sort Array to be Sorted: A

Selection sort is a simple sorting algorithm. This sorting algorithm is an in-place comparison-based algorithm in which the list is divided into two parts, the sorted part at the left end and the unsorted part at the right end. Initially, the sorted part is empty and the unsorted part is the entire list.

Shellsort Invented by Donald Shell
Shellsort Invented by Donald Shell

Shell Sort is a generalized version of insertion sort. It is an in–place comparison sort. Shell Sort is also known as diminishing increment sort, it is one of the oldest sorting algorithms invented by Donald L. Shell (1959.) This algorithm uses insertion sort on the large interval of elements to sort.

source: codingeek.com

Related Types