logo

Crowdly

Browser

Add to Chrome

Qual a complexidade temporal do método allDiff no pior caso? // What is the w...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

Qual a complexidade temporal do método allDiff no pior caso? //

What is the worst-case time complexity of the method allDiff?

/**

*

* @param numbers : an array that is filled up to position n-1

* @return true iff all the numbers are different

*/

public static boolean allDiff(int[] numbers,int n) {

int i=0;

while (i<n && diff(numbers[i],numbers,i,n))

i++;

return i==n;

}

private static boolean diff(int number, int[] numbers, int pos, int n) {

int i=pos+1;

while (i<n && number!=numbers[i])

i++;

return i==n;

}

100%
0%
0%
0%
0%
More questions like this

Want instant access to all verified answers on moodle.fct.unl.pt?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome