AllDistinct(a1 , . . . , an )
if (n = 1)
return True
for i := n down to 2
begin
if (LinearSearch(a1 , . . . , ai−1 ; ai ) != 0)
return False
end
return True
Give a big-O bound on the running time of AllDistinct. For full credit, you must show work or briefly explain your answer.
So the actual answer for this according to the solution for this problem is O(n^2). However, since BigO is the worst case running time, could I have answered O(n^100000) and gotten away with it? Theres no way they can take points off for that since its technically the correct answer right? Although the more useful O(n^2) is obvious in this algorithm, I ask because we might have a more difficult algorithm on the upcoming exam, and incase I cant figure out the 'tight' bound, I could make up some extremely large value and it should still be correct, right?