Posts

Showing posts with the label Merge Sort

Merge Sort

Time Complexity - O(nLogn) || Space Complexity - O(n) [Due to two temp arrays taken to store left and right subpart] It follows a divide and conquer strategy It is a stable sort Java 6 and below versions of Java used merge sort in for their inbuilt .sort() method __________________________________________________________________________________________________________________________________________________________________ public class Main {          public static void mergeSort(int[] arr, int left, int right){         // if left is less than right, it means there is more than 1 element. Hence, this problem can be broken down into smaller sub-problems         if(left<right){             // we find the mid first and break this array into 2 parts around mid             int mid = (left+right)/2;           ...