java - Why is a Hash Table with linked lists considered to have constant time complexity? -
in comp class last night learned hashing , how works when trying find element x in hash table.
our scenario have dataset of 1000 elements inside our table , want know if x contained within table.
our professor drew java array of 100 , said store these 1000 elements each position of array contain pointer linked list keep our elements.
assuming hashing function mapped each of 1000 elements value between 0 , 99 , stored element @ position in array, there 1000/100 = 10 elements contained within each linked list.
now know whether x in table, hash x, find it's hash value, lookup array @ slot , iterate on our linked list check whether x in table.
my professor concluded saying expected complexity of finding whether x in table o(10) o(1). cannot understand how case. in mind, if dataset n , array size n takes on average n/n steps find x in table. isn't definition not constant time, because if scale data set time still increase?
i've looked through stack overflow , online , says hashing expected time complexity of o(1) caveats. have read people discuss chaining reduce these caveats. maybe missing fundamental determining time complexity.
tldr: why take o(1) time lookup value in hash table when seems still determined how large dataset (therefore function of n, therefore not constant).
in mind, if dataset n , array size n takes on average n/n steps find x in table.
this misconception, hashing requires calculate correct bucket (in case, array index) object should stored in. calculation not become more complex if size of data set changes.
these caveats speak of hash collisions: multiple objects share same hashcode; these can prevented better hash function.
Comments
Post a Comment