Quelqu'un pourrait-il expliquer comment fonctionne un ensemble non ordonné? Je ne suis pas sûr non plus comment fonctionne un ensemble. Ma question principale est quelle est l'efficacité de sa fonction de recherche.Unordered_set questions
Par exemple, quel est le temps d'exécution total du gros O?
vector<int> theFirst;
vector<int> theSecond;
vector<int> theMatch;
theFirst.push_back(-2147483648);
theFirst.push_back(2);
theFirst.push_back(44);
theSecond.push_back(2);
theSecond.push_back(-2147483648);
theSecond.push_back(33);
//1) Place the contents into a unordered set that is O(m).
//2) O(n) look up so thats O(m + n).
//3) Add them to third structure so that's O(t)
//4) All together it becomes O(m + n + t)
unordered_set<int> theUnorderedSet(theFirst.begin(), theFirst.end());
for(int i = 0; i < theSecond.size(); i++)
{
if(theUnorderedSet.find(theSecond[i]) != theUnorderedSet.end())
{
theMatch.push_back(theSecond[i]);
cout << theSecond[i];
}
}
Efficacité! = Big O. –
les réponses ont couvert votre question, ou quelque chose n'est pas encore clair? – juanchopanza