What is the time complexity of Java hashCode method for the String class? -
is java's hashcode method string class computed in constant time or linear time? algorithm used?
the documentation tells function:
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
it's computed once using linear-time pass, , cached it's o(1) retrieve in future.
Comments
Post a Comment