Time Complexity of HashMap methods

前端 未结 5 1025
走了就别回头了
走了就别回头了 2020-12-13 19:21

Since i\'m working around time complexity, i\'ve been searching through the oracle Java class library for the time complexity of some standard methods used on Lists, Maps an

5条回答
  •  春和景丽
    2020-12-13 20:04

    Search: O(1+k/n)
    Insert: O(1)
    Delete: O(1+k/n) where k is the no. of collision elements added to the same LinkedList (k elements had same hashCode)

    Insertion is O(1) because you add the element right at the head of LinkedList.

    Amortized Time complexities are close to O(1) given a good hashFunction. If you are too concerned about lookup time then try resolving the collisions using a BinarySearchTree instead of Default implementation of java i.e LinkedList

提交回复
热议问题