SORTING ALGORITHM

INSERTION SORT

MERGE SORT

QUICK SORT

HEAP SORT

 

INSERTION SORT

  •  Stable
  • O(1) extra space
  • O(n2) comparisons and swaps
  • Adaptive: O(n) time when nearly sorted
  • Very low overhead 

MERGE SORT

  •  Stable
  • Θ(n) extra space for arrays (as shown)
  • Θ(lg(n)) extra space for linked lists
  • Θ(n·lg(n)) time
  • Not adaptive
  • Does not require random access to data 

 

QUICK SORT

  •  Not stable
  • O(lg(n)) extra space (see discussion)
  • O(n2) time, but typically O(n·lg(n)) time
  • Not adaptive 

 

public void quicksort(int[] list, int low, int high) 
{
    if (low < high) {
        int mid = partition(list,low,high);
        quicksort(list,low,mid-1);
        quicksort(list,mid+1,high);
    }
}

HEAP SORT

  •  Not stable
  • O(1) extra space (see discussion)
  • O(n·lg(n)) time
  • Not really adaptive 

 

 

Sorting Algorithm

By Syafiq bin abdul rahman