Merge-Sort

Merge Sorting

Merge sorting also works on the principle of "divide and conquer".The algorithm of merge sort is quite different from that of quick-sort but its best case performance is also O(nlog(n)).The step by step process is-

  1. Divide the unsorted list into n sublists, each containing 1 element (a list of 1 element is considered sorted).
  2. Repeatedly merge sublists to produce new sorted sublists until there is only 1 sublist remaining. This will be the sorted list.
How it is actually implemented is described here....
  1. Firstly divide the given array of n elements into n individual numbers.
  2. Then compare the adjacent elements and merge them in the sorted order.
  3. Then compare the corresponding elements of the resulting lists and arrange them in the sorted order.
  4. And finally the sorted list will be obtained.
The following link will help you in understanding it.

Want to see the example code..??
CLICK HERE

Complexity Analysis of Merge Sort

Worst Case Time Complexity : O(n log n)
Best Case Time Complexity : O(n log n)
Average Time Complexity : O(n log n)
Space Complexity : O(n)
  • Time complexity of Merge Sort is O(n Log n) in all 3 cases (worst, average and best) as merge sort always divides the array in two halves and take linear time to merge two halves.
  • It requires equal amount of additional space as the unsorted list. Hence its not at all recommended for searching large unsorted lists.
  • It is the best Sorting technique for sorting Linked Lists.

Comments

Popular posts from this blog

Search box for blog or website

Image Search Engine Using Python

Cordova viewport problem solved