I've a hashtable which consists of 1000 elements and 100 buckets with maximum 100 entries per bucket. Suppose one bucket has 100 entries (i.e. 100 items in the list of that bucket). Now what will be the time complexity in terms of big-O notation if the item I sought is the 100th in the list of the bucket. O(100) or O(n)? Or anything else?
The point of big-O notation is that you do not "suppose one bucket has 100 entries", you let the number of its entries be n
, and get an expression in terms of n
.
For n
entries in the list, the time complexity will be O(n)
, ignoring whatever hash function you're using.
Note that this is worst case (the last item), and on average the search runs in O(1)
.