Worst-Case Lookup and Tree Buckets
Worst-case Hash Table lookup is O(n) because a malicious or pathological key distribution can place many entries in the same bucket. A lookup may then need to inspect every entry in that bucket. Some modern separate-chaining implementations convert sufficiently large buckets from linked structures into balanced search trees, reducing bucket lookup from linear to logarithmic time.
Good hash distribution normally keeps bucket sizes small.
Treeification protects against pathological collision chains in some implementations.
Tree-based buckets can provide O(log k) lookup within a bucket.
Treeification has additional memory and comparison overhead.
The exact thresholds and implementation strategy are library-specific.
This optimization does not mean all Hash Table operations are unconditionally O(log n); expected behavior remains approximately O(1).