# Trying Improve Mma Method Number Comparisons 3n 2 2 Method Attach Give Number Comparison Q10373077

I am trying to improve my mmA method such that the number ofcomparisons is ⌈3n/2−2⌉. the method I attach below only give me thenumber of comparison is 2+C(⌊n/2⌋)+C(⌈n/2⌉). My improved methodmust still take into parameter ( int lowerBound, int upper bound ,int [] array) and must still be recursive- no loops. please help,thank you

public class MinMax {

public static void main(String[] args) {
int[] array = new int[]{4, 7, 2, 10, 345, 28, 1, 5, 0, -10, -4098,23, 0};

Pair expected = new Pair(-4098, 345);
Pair actual = MinMax.mmB(0, array.length-1, array);
if (actual.alpha != expected.alpha) {
System.out.println(“Min value incorrect. Expected:”+expected.alpha+” but got: “+actual.alpha);
} else if (actual.omega != expected.omega) {
System.out.println(“Max value incorrect. Expected:”+expected.omega+” but got: “+actual.omega);
} else {
System.out.println(“Test Passed”+actual.alpha +” “+actual.omega);
}
}

public static Pair mmA(int lB, int uB, int[] array){
if (uB == lB){
return new Pair(array[lB], array[uB]);
}
else if (uB – lB == 1) {
int smallest = Math.min(array[lB], array[uB]);
int largest = Math.max(array[lB], array[uB]);
return new Pair(smallest, largest);
}
else {
int mid = (lB + uB)/2;
Pair First = mmA(lB, mid, array);
Pair Next = mmA(mid+1, uB, array);
int smallest = Math.min(First.alpha, Next.alpha);
int largest= Math.max(First.omega, Next.omega);
return new Pair(smallest, largest);
}
}

“We Offer Paper Writing Services on all Disciplines, Make an Order Now and we will be Glad to Help”

0 replies