There is a points given in two dimensional plane and I want to count maximum collinear points for that I calculated all possible lines slopes and their intercepts.
To solve this problem, I tried to build a hash table but i am unable to find a hash function by which I can easily point all collinear points in one hash key. So help me to find out hash function that fits for this scenario?
There is a points given in two dimensional plane and I want to count
Share
This is not possible, because colinearity is not transitive. I.e., lets say A B and C lie on a line (i.e. are colinear). Therefore, A B and C should get the same hash key. Next, C D and E also lie on another line. Therefore, C D and E should also get the same hash key. Consequently, A B receive the same hash key as D and E, which is wrong because these points are not colinear.
In addition, colinearity is defined on sets of points, so my above definition is rather vague. I.e. you cannot say A and B are colinear (well, you can, but if you only regard two points, each pair of points is colinear).
What you can do is save the sets of colinear points in a hash map. Then, a good hash function would simply consist of the slope s and ordinate intercept i. For example, you could use s * 31i. This hash map can be used to add new points to the sets and finally count the size of the sets to retrieve your answer.