Big-O Analysis Example
Hi All,
I'm working through one of the examples in the Big-O Analysis section, in which they analyze the CompareToAll implementation that returns the largest integer in an array. The book states:
"For now, assume that the maximum element is at the end of the array. In this case, this function may compare each of n elements to n other elements. Thus, there are n ( n examinations, and this is an O( n 2 ) algorithm."
However, the outer for loop checks the end of the array first, so wouldn't the inner loop just run through once before the method breaks out of the outer for loop, making it just n examinations?
Thanks for helping me clarify this!
|