-1

I need a data structute that allows

  • addPoint(x, y) in O(logN)
  • printDiameter() in O(logN)

where N is the current number of points in the polygon.
Obviously the two points will lie on the convex hull of the polygon. Using concept of anti-nodal pairs(Rotating-Callipers), we can find the diameter of N points is O(N).
This explains neatly the O(n) solution, but it doesn't supports insertion of point.

maverick
  • 119
  • 4

1 Answers1

0

A k-d tree could do insertion in O(logN) as long as it's balanced in some way. For the diameter part, you would have to check every node in order to find the farthest, so it should be O(N). Another solution would be to use a QuadTree, and traverse it in order to obtain only the nodes located at the external part of the tree.

Community
  • 1
  • 1
avilagab
  • 13
  • 6