Question

Please see this question and the accepted answer:

Algorithm to calculate number of intersecting discs

Instead of using a binary tree, what if you were to use an array, sort it and then simply iterate up through the array? Would it still be O(n log n)?

Iterating through the sorted array (to me) seems like it would be O(n^2)....

Was it helpful?

Solution

The accepted answer speaks about binary search over a sorted array, not about a binary tree. Binary search is logn, "simply iterating" is n. So you would make the solution O(n^2) indeed. But there is no point in simple iteration over an array that you know is sorted - you can use binary search.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top