I am completely familiar on how hashtables and hashes work but I am trying to fully understand how the O(1) completely comes from.
set1 = {'s','t'}
print('x' in set1)
print('s' in set1)
set2 = {'s'}
print('s' in set2)
I am told that to check if 's'
is in set1, if will check the memory allocation of the hash of 's'
, and check if it is in set1 in O(1) and return the boolean. Therefore two O(1) operations, but my question is: How does the hashes actually work indepth. What I mean by this is, when you hash 's'
, does that hash have something like set1
and set2
and you're checking if set1
is either set1
or set2
, or does each set have a different hash of 's'
and you're checking the hash of 's'
for each different set.