Saturday, February 22, 2014

Merge Sort in Java

Refer: Main indexed article on sorting.

Merge Sort  is an O(n log n) comparison-based sorting algorithm.
It is a divide and conquer algorithm.

How does Merge Sort work?

Divide the unsorted list into n sublists, each containing 1 element (a list of 1 element is considered sorted).



Repeatedly merge sublists to produce new sorted sublists until there is only 1 sublist remaining. This will be the sorted list.




Java Code Snippet

Step 1. Divide the unsorted list into n sublists, each containing 1 element (a list of 1 element is considered sorted).



Step 2. Repeatedly merge sublists to produce new sorted sublists until there is only 1 sublist remaining. This will be the sorted list.



Step 3. Code run output

No comments:

Post a Comment