Scenario
Merge sorting is one of the fastest sorting techniques. It is used in many bundled libraries and APIs. In this activity, we will write an algorithm in Java to sort an array using merge sort.
Aim
To use the pseudocode shown in this section to implement the full merge sort algorithm in Java.
Prerequisites
To solve this activity, you have to implement the methods found in the following class, which is available on the GitHub repository for the book at the following path:
If you have your project set up, you can run the unit test for this activity by running the following command:
gradlew test --tests com.packt.datastructuresandalg.lesson2.activity.mergesort*
Steps for Completion
- Start from the mergeSort method, which splits the array in two, recursively sorts both, and merges the result
- Then, implement the merge method, which merges both ends of the split array into another space
- After the merge is done, copy the new array back in place of the input array