String Hashing vs N-D array ? comparison

Recently I learned about string hashing in place of N-D arrays for memotization.I wonder which is better and more efficient?Any justification?

Use case:-
Suppose I need to memotize a state having statevariables as x,y and z.

if using string hashing:-

string  hsh= to_string(x)+to_string(y)+to_string(z);
unordered_set/map<string> mp;

if using N-D array i.e 3D in this case then it will be :-

vector<vector<vector<int>>> vec;

Which of the following approach is better?

Comments (0)