mardi 21 janvier 2020

Which is faster: Searching by string in 1d vector or searching by vector in 2d vector?

I am wondering which data storage method is faster in terms of searching. Keep in mind these structures are unsorted. For example, I store my data like this:

vector<vector<int >> vals;
vals.push_back({1,2,3});

and I want to search if

{1,2,3} 

is in my vector.

I can also store my data like this:

vector<string> vals;
vals.push_back("1 2 3");

and search if

"1 2 3"

is in my vector.

Which of these methods, in terms of both time and space, is more efficient?

Aucun commentaire:

Enregistrer un commentaire