You are given a set of n points on the number line. They are given in arbitrary order. The task is to find the points that are closest to each other.
You are given a set of n points on the number line. They are given in arbitrary order. The task is to find the points that are closest to each other.
To solve the problem you decide to take one point and compute its distance to all other points and repeat this process for all points. During the process you track the closest pair.
What is the running time of this algorithm ?
- O(nlgn)
- O(n^2)
- Runtime is independent of n.
- O(log n)
.
Comments
Post a Comment