samedi 28 mars 2015

intersection of n vectors

I'm new to programming and I've recently come across an issue with finding the intersection of n vectors, (int vectors) that are unordered. The approach that I came up with has a complexity of O(n^2) and I am using the std::set_intersect function.


The approach that I came up with is by having two vectors: the first vector would correspond to the first vector that I have, and the second would be the second vector. I call set intersection on the two and overwrite to the first vector, then use the vector clear function on the second. I then overwrite the next vector to the second, and repeat the process, and eventually returning the first vector.


I do believe there is a more efficient way of going about this, but at the moment, I can not think of a more efficient manner. Any help on this issue would be much appreciated.


Aucun commentaire:

Enregistrer un commentaire