Recently, a publication was published in which the following question was asked:
You have a two-dimensional plane (X, Y) of coordinates. A group of random points is selected. You need to select the maximum possible set of selected points, so that no two points have an X coordinate, and two points do not have a Y coordinate.
This is all the information that has been provided.
Two possible solutions were presented.
One of them suggested using the maximum flow algorithm, so that each selected point is mapped to a path connecting (source โ X โ Y โ receiver). This is done in O (V 3 ) time, where V is the number of selected vertices.
Another (mine) suggested using the Hungarian algorithm. Create an n ร n matrix from 1s, then set each selected (x, y) coordinate to 0. The Hungarian algorithm will give you the lowest cost for this matrix, and the answer is the number of selected coordinates equal to 0. This is done in O (n 3 ) the time where n is greater than the number of rows or the number of columns.
My reasoning is that in the vast majority of cases, the Hungarian algorithm will be faster; V is n in the case where one selected point for each row or column, and substantially more for any case where there is something more: for a given 50 ร 50 matrix with half the selected coordinates, V is 1250, and n is 50.
, , 10 9 ร 10 9 , V 2, n - 1 000 000 000. , .
: , , ( ) , , , ?