algorithm - How to find two most distant points? -


this question asked on job interview time ago. , still can't figure out sensible answer.

question is:

you given set of points (x,y). find 2 distant points. distant each other.

for example, points: (0,0), (1,1), (-8, 5) - distant are: (1,1) , (-8,5) because distance between them larger both (0,0)-(1,1) , (0,0)-(-8,5).

the obvious approach calculate distances between points, , find maximum. problem is o(n^2), makes prohibitively expensive large datasets.

there approach first tracking points on boundary, , calculating distances them, on premise there less points on boundary "inside", it's still expensive, , fail in worst case scenario.

tried search web, didn't find sensible answer - although might lack of search skills.

edit: 1 way find convex hull http://en.wikipedia.org/wiki/convex_hull of set of points , 2 distant points vertices of this.

possibly answered here: algorithm find 2 points furthest away each other

also:


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -