Skip to content

Commit bbdfe40

Browse files
committed
merge sort implementation - O(nlogn)
1 parent 5395aa3 commit bbdfe40

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

CodingBlocks Training/Day14/mergeSort.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ public static void main(String[] args) {
77
int[] arr = { 80, 10, 50, 30, 60, 40, 20, 70 };
88

99
int start = 0, end = arr.length - 1;
10-
int[] sorted = quickSort(arr, start, end);
10+
int[] sorted = mergeSorting(arr, start, end);
1111
display(sorted); // 10 20 30 40 50 60 70 80
1212

1313
}
1414

15-
public static int[] quickSort(int[] arr, int start, int end) {
15+
public static int[] mergeSorting(int[] arr, int start, int end) {
1616
if (start == end) {
1717
int[] baseResult = new int[1];
1818
baseResult[0] = arr[start];
1919
return baseResult;
2020
}
2121
int mid = (start + end) / 2;
22-
int[] firstHalf = quickSort(arr, start, mid);
23-
int[] secondHalf = quickSort(arr, mid + 1, end);
22+
int[] firstHalf = mergeSorting(arr, start, mid);
23+
int[] secondHalf = mergeSorting(arr, mid + 1, end);
2424
int[] sortedArray = mergeArray(firstHalf, secondHalf);
2525

2626
return sortedArray;

0 commit comments

Comments
 (0)