Final answer:
To check if all elements of an array are distinct, a nested loop is used to compare each element with others, resulting in an upper bound of O(n^2) comparisons in the worst case.
Step-by-step explanation:
To check if all elements in an array are distinct, you can compare each element with the rest of the elements for any duplicates. In the worst case, you'd have to compare each element with every other element in the array. This results in an upper bound of the number of comparisons, which can be represented using Big O notation as O(n2), where 'n' is the number of elements in the array.
Here is an example code in Python to illustrate this:
def are_elements_distinct(arr):
for i in range(len(arr)):
for j in range(i + 1, len(arr)):
if arr[i] == arr[j]:
return False
return True
The function are_elements_distinct returns True if all elements are distinct, otherwise it returns False. The main basic operation here is the comparison arr[i] == arr[j], which in the worst case occurs when the array does not have any duplicates and thus every possible pair is compared once.