ALGORITHM Unique Elements (A[0..n-1]) //Determines whether all the elements in a given array are distinct //Input: An array A[0..n - 1] //Output: Returns "true" if all the elements in A are distinct and "false" otherwise 11 for i 0 to n - 2 do for ji+1 to n - 1 do if A[i] = A[j] return false return true A random list of 20 numbers is generated and used as input for the algorithm UniqueElements. Which of the following is NOT true when the algorithm terminates? OA. in the best case the first two elements are the same. B. in the worst case, there are no duplicate elements. C. in the worst case the number of comparisons is 190 D. in the worst case the number of comparisons is 400

icon
Related questions
Question
ALGORITHM Unique Elements (A[0..n-1])
//Determines whether all the elements in a given array are distinct
//Input: An array A[0..n-1]
//Output: Returns "true" if all the elements in A are distinct
and "false" otherwise
//
for i 0 to n - 2 do
for ji+1 to n - 1 do
if A[i] = A[j] return false
return true
A random list of 20 numbers is generated and used as input for the algorithm
UniqueElements. Which of the following is NOT true when the algorithm
terminates?
OA. in the best case the first two elements are the same.
B. in the worst case, there are no duplicate elements.
C. in the worst case the number of comparisons is 190
D. in the worst case the number of comparisons is 400
Clear my choice
Transcribed Image Text:ALGORITHM Unique Elements (A[0..n-1]) //Determines whether all the elements in a given array are distinct //Input: An array A[0..n-1] //Output: Returns "true" if all the elements in A are distinct and "false" otherwise // for i 0 to n - 2 do for ji+1 to n - 1 do if A[i] = A[j] return false return true A random list of 20 numbers is generated and used as input for the algorithm UniqueElements. Which of the following is NOT true when the algorithm terminates? OA. in the best case the first two elements are the same. B. in the worst case, there are no duplicate elements. C. in the worst case the number of comparisons is 190 D. in the worst case the number of comparisons is 400 Clear my choice
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer