need help with this java program directions: Implement a recursive version of me
ID: 3816354 • Letter: N
Question
need help with this java program
directions:
Implement a recursive version of merge sort and a merge “helper” method. Add functionality to your code to count the total number of times all loops in your merge method execute and display this number when the sort is finished. Call your recursive merge sort algorithm with four different arrays: a 10 item array that is the best case for the algorithm, a 10 item array that is the worst case for the algorithm, a 100 item array that is the best case for the algorithm, and a 100 item array that is the worst case for the algorithm. Note: you will not receive credit if your implementation does not count the number of iterations that are done by loops in your merge.
It is ok to do this count as a global variable. Hint: Since the best and worst case time complexity of merge sort is the same, the number of iterations for the best and worst case of each array size should be equal.
Example code
int[] test1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
System.out.println(Arrays.toString(mergeSort(test1)));
System.out.println(iterations + " iterations”);
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
34 iterations
Explanation / Answer
void merge(int *a, int *b, int low, int pivot, int high) { int h,i,j,k; h=low; i=low; j=pivot+1; while((hRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.