C ++: efficient way to check if elements in a vector are greater than elements in another that have the same indices?
I have it vector < vector <int> >
like this:
v = {{1,2,3}, {4,2,1}, {3,1,1}....}}
All the elements v
, such as v[0]
, v[1]
, v[2]
... are the same size. There may be duplicate items.
I am trying to find and remove vectors (for example v[2]
) that are "majorized" by another vector (for example v[1]
), i.e. all elements v[1]
greater than / equal to the corresponding elements (in index order) in v[2]
.
A naive way to do this would be to walk through v
and compare each vector to another vector, and additionally compare each element to another vector element.
But I believe the best way to do this is without getting O(n^3)
all the vectors in the element count v
.
If multiple vectors are equal, I only need one of them (i.e. remove all but one). A random selection would be enough.
Any thoughts or ideas are appreciated!
source to share
These are called point set maxima . For two and three dimensions, this can be solved in O (n log n) time. For more than three dimensions, this can be solved in O (n (log n) ^ (d - 3) log log n) time. A linear expected time algorithm is available for random points.
source to share