2

I have an unsorted array of (x,y) coordinates and need to find the min/max for both (x) and (y) separately so that I can build a bounding box using $O(\frac{3n}{2})$ comparisons.

If I use this method to find the min/max for the left/fight box boundaries, then use the same algorithm to find min/max of y for the top/bottom boundaries, does this double the amount of comparisons or can I still claim it’s $O(\frac{3n}{2})$?

D.W.
  • 167,959
  • 22
  • 232
  • 500
adamcasey
  • 35
  • 3

1 Answers1

1

does this double the amount of comparisons or can I still claim it’s $O(3n/2)$?

You misunderstand the big $O$ notation.

Even if you double or quadruple the amount of comparisons, you can still claim it is $O(3n/2)$. That is, the amount of comparisons as a function of $n$ is asymptotically not bigger than $3n/2$. The very purpose of big $O$ notation is to hide a constant factor so that it becomes clearer what is the asymptotic picture. In fact, $O(3n/2)$ = $O(n)$. When I write "=", I mean equality. That is, the left hand side and the right hand side represent exactly the same set of functions.

Here is what you could say.

If I use this method to find the min/max for the left/right box boundaries and then use the same algorithm to find min/max of y for the top/bottom boundaries, I will use $2(\lceil 3n / 2\rceil - 2) \le 3n -3$ comparisons. That is, I will use $O(n)$ comparisons.

John L.
  • 39,205
  • 4
  • 34
  • 93