I am doing a research where I have stuck in solving a algorithm in efficient manner.I would be really helpful if someone help me out in this -
Algo -
I have a set of points (x1,y1) , (x2,y2)...(can be 10000 points). I would like to print points in a group - which can be enclosed by a rectangle of 10x10.
Examples -
p1 (10,10)
p2 (15,15)
p3 (40,100)
p4 (40,50)
p5 (40,90)
p6(200,200)
p7(400,350)
output
gp1 -> p1 (10,10), p2 (15,15)
gp2 -> p3 (40,100), p5 (40,90)
Explanation - point p1 and p2 will fall in a rectangle if a rectangle of 10x10 starts from point p1. Similar p3 & p5 will fall in a rectangle of 10x10 if rectangle will start from point p3. It would also be helpful if we can find out the co-ordinate of each rectangle enclosing them.
Note: A single Point can belong to 2 different group..in this case all will be treated a single group and then size of rectangle will grow
What I tried -
I tried to take point p1 co-ordinate and compare its x & y with others. if i found point p2 near to it. I add them in a group and then skip p2 from comparing others. i start process again with p3.
It doesn't seems a efficient solution as in worst case it can have nxn complexity which is very bad.
Note: I request you all to please do not consider this as a homework as it is not.