0
I’m having trouble making a division and conquest algorithm of the sum of the elements of an arrangement.
public static int somatorio(int[] a, int numElem) {
if(numElem == 0) {
return 0;
}else if(numElem == 1){
return a[0];
}
int meio = numElem/2;
int dTamanho = numElem - meio; //tamanho lado direito
int eSoma = somatorio(a, meio); //soma lado esquerdo
int dSoma = somatorio(a, dTamanho); //soma lado direito
return eSoma + dSoma;
}
I’m not able to perform this sum recursively, how can I fix my code?
First, it has no division and no conquest, it has division, it has complication and it does the same thing as not divided. Second: because it does not iterate that much easier, and without division?
– Maniero
College job ahhahah. I’m having a hard time with this part.... would then have some tip on how to improve this code or where I can get information?
– Maurício