Activity: Implementing Merge Sort in Java

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:

https://github.com/TrainingByPackt/Data-Structures-and-Algorithms-in-Java/blob/master/src/main/java/com/packt/datastructuresandalg/lesson2/activity/mergesort/MergeSort.java


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

  1. Start from the mergeSort method, which splits the array in two, recursively sorts both, and merges the result
  2. Then, implement the merge method, which merges both ends of the split array into another space
  3. After the merge is done, copy the new array back in place of the input array
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset