Determine whether the two classes are linearly separable (algorithmically in 2D)

前端 未结 9 1966
一向
一向 2020-12-13 11:09

There are two classes, let\'s call them X and O. A number of elements belonging to these classes are spread out in the xy-plane. Here is an example where the two classes are

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-13 11:26

    Here is a naïve algorithm that I'm quite sure will work (and, if so, shows that the problem is not NP-complete, as another post claims), but I wouldn't be surprised if it can be done more efficiently: If a separating line exists, it will be possible to move and rotate it until it hits two of the X'es or one X and one O. Therefore, we can simply look at all the possible lines that intersect two X'es or one X and one O, and see if any of them are dividing lines. So, for each of the O(n^2) pairs, iterate over all the n-2 other elements to see if all the X'es are on one side and all the O's on the other. Total time complexity: O(n^3).

提交回复
热议问题