public class SortAlgorithm {
public static void sorting(int[] A){
quickLevel_sort(A, 0, A.length - 1);
}
private static void mergeLevel_Sort(int[] A, int begin, int end) {
if (begin < end) {
int middle = (begin + end) / 2;
quickLevel_sort(A, begin, middle);
quickLevel_sort(A, middle + 1, end);
merge(A, begin, middle, end);
}
}
private static void quickLevel_Sort(int[] A, int begin, int end) {
if (begin < end) {
int middle = partition(A, begin, end);
mergeLevel_sort(A, begin, middle - 1);
mergeLevel_sort(A, middle + 1, end);
}
}}
I want to find the complexity of this function, but it isn't very clear because mergelevel and quicklevel are calling each other recursively. I hope someone can give me some tips
The "merge" function is used in merge sort to merge two sorted arrays, working in O(n) time complexity. The "partition" function, used in quicksort, selects the first element as the pivot and finds its correct location in the array, placing it there. Its complexity is also O(n).