You are on page 1of 2

Bubble Sort

Bubble sort is a simple sorting algorithm. It works by repeatedly stepping through the list
to be sorted, comparing each pair of adjacent items and swapping them if they are in the
wrong order. The pass through the list is repeated until no swaps are needed, which
indicates that the list is sorted. The algorithm gets its name from the way smaller
elements "bubble" to the top of the list. Because it only uses comparisons to operate on
elements, it is a comparison sort.

Worst case performance О(n²) Best case performance О(n²) Average case performance
О(n²)

Selection Sort

1. Find the minimum value in the list


2. Swap it with the value in the first position
3. Repeat the steps above for the remainder of the list (starting at the second position
and advancing each time)

Worst case performance О(n²) Best case performance О(n²) Average case performance
О(n²)

Insertion Sort

If the first few objects are already sorted, an unsorted object can be inserted in the sorted
set in proper place. This is called insertion sort. An algorithm consider the elements one
at a time, inserting each in its suitable place among those already considered (keeping
them sorted).
Worst case performance О(n2) Best case performance O(n) Average case performance
О(n2)

Quick Sort
Quicksort sorts by employing a divide and conquer strategy to divide a list into two sub-
lists.
The steps are:
1. Pick an element, called a pivot, from the list.
2. Reorder the list so that all elements which are less than the pivot come before the
pivot and so that all elements greater than the pivot come after it (equal values can
go either way). After this partitioning, the pivot is in its final position. This is
called the partition operation.
Recursively sort the sub-list of lesser elements and the sub-list of greater elements.

Worst case performance Θ(n2) Best case performance Θ(nlogn) Average case
performance Θ(nlogn)
HEAP SORT:-
Heapsort complexity is always O(n log n)
Quicksort is usually O(n log n) but in the worst case slows to O(n2)
Quicksort is generally faster, but Heapsort is better in time-critical applicationsHEAP
SORT:-

Definitions of heap:
A large area of memory from which the programmer can allocate blocks as needed, and
deallocate them (or allow them to be garbage collected) when no longer needed
A balanced, left-justified binary tree in which no node has a value greater than the value
in its parent.
A heap is a list in which each element contains a key, such that the key in the element at
position k in the list is at least as large as the key in the element at position 2k and 2k + 1
if exist.
Worst case performance Θ(nlogn) Best case performance Θ(nlogn) Average case
performance Θ(nlogn)

MERGE SORT:-
MergeSort uses divide & conquer strategy to sort the elements.
Here, you go on dividing till only one element is left.
Then this element will be merged with the next one and both will be put in correct order
and since this is a recursive function, it will be repeated till you complete the merge and
come out.
So, here is the sequence of calls:
a[] = {3, 5, 2, 6, 8}
low = 0; high = 4;
mergesort(a, 0, 4)
mid = 0 + 4 / 2 = 2
mergesort(a, 0, 2)
mergesort(a, 3, 4)
merge(a, 0, 4, 2)
So, each of the mergesort() calls will again go back and call mergesort() and merge(),
this goes on till: (low < high) is satisfied.
In the example you have taken there are only 5 elements and is very easy to simulate
Worst case performance Θ(nlogn) Best case performance Θ(nlogn) Average case
performance Θ(nlogn)

RADIX SORT:-
In computer science, radix sort is a sorting algorithm that sorts integers by processing
individual digits, by comparing individual digits sharing the same significant position. A
positional notation is required, but because integers can represent strings of characters
(e.g., names or dates) and specially formatted floating point numbers, radix sort is not
limited to integers
Two classifications of radix sorts are least significant digit (LSD) radix sorts and most
significant digit (MSD) radix sorts.
complexity of radix sort is O(k*N), where k is a constant.

You might also like