Hash Table v/s Trees

前端 未结 4 485
醉话见心
醉话见心 2021-01-06 03:13

Are hashtables always faster than trees? Though Hashtables have O(1) search complexity but suppose if due to badly designed hash function lot of collisions happen and if we

4条回答
  •  不思量自难忘°
    2021-01-06 03:47

    If due to badly designed hash function lot of collisions happen and if we handle collisions using chained structure (say a balanced tree) then the worst case running time for search would be O(n) (not O(log n)). Therefore you cannot conclude for big or small data sets even in case of worst case scenarios hash tables will always be faster than trees.

提交回复
热议问题