/*This is a Java Program to implement Merge Sort on an integer array. Merge sort is an O(n log n) comparison-based sorting algorithm. Most implementations produce a stable sort, which means that the implementation preserves the input order of equal elements in the sorted output. Merge sort is a divide and conquer algorithm that was invented by John von Neumann in 1945. Conceptually, a merge sort works as follows : i) Divide the unsorted list into n sublists, each containing 1 element (a list of 1 element is considered sorted). ii) Repeatedly merge sublists to produce new sublists until there is only 1 sublist remaining. This will be the sorted list. Worst case performance : O(n log n) Best case performance : O(n log n) Average case performance : O(n log n)*/ /* * Java Program to Implement Merge Sort */ import java.util.Scanner; /* Class MergeSort */ public class MergeSort { /* Merge Sort function */ public static void sort(int[] a, int low, int high) { int N = high - low; if (N <= 1) return; int mid = low + N/2; // recursively sort sort(a, low, mid); sort(a, mid, high); // merge two sorted subarrays int[] temp = new int[N]; int i = low, j = mid; for (int k = 0; k < N; k++) { if (i == mid) temp[k] = a[j++]; else if (j == high) temp[k] = a[i++]; else if (a[j]