0

Is it only O(1) when there are no collision. Im talking about a hash table that has Linked Lists in each slot to hold the values.

Robert
  • 1
  • 1
  • The dictionary lookup is obviously constant time. The collision lookup can be made small and essentially constant by using a decent hash function with enough slots. – ditkin Jan 28 '15 at 05:01

2 Answers2

1

The average number of collisions is O(1), and if your hash function is essentially random you can prove that it's extremely improbable that there are many collisions.

Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413
1

Yes it is O(1) if you have unique hash for keys and LinkedList or Binary Tree has only one item,

With Java 7 collision resolves to binary tree instead of LinkedList so it is not O(N) for collision

jmj
  • 237,923
  • 42
  • 401
  • 438