# Does simultaneously finding max/min in array of coordinates by x and y increase comparisons?

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})$$?

• "I sort the array first by the x-coordinates", which implies you have used $\Theta(n\log n)$ comparisons. You just do not do that step. Please update your question accordingly. – John L. Nov 28 '18 at 3:50
• @Apass.Jack thanks for pointing that out – adamcasey Nov 28 '18 at 3:54
• Please don't destroy/replace the content of your question. Part of our mission is to build up questions and answers that will be useful not only to you but hopefully to others in the future as well. Thank you! – D.W. Dec 4 '18 at 4:37
• (My spelling checker doesn't flag left / fight.) – greybeard Dec 4 '18 at 8:00

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.
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.