- Adding an item to an ArrayList in Java is O(1), but the worst case for an add operation in ArrayList is O(n)
- Complexity: O(N)
- Displaying a whole ArrayList in Java is O(N) as there could be ten or millions of object in an arrayList.
- Complexity: O(N)
- With HashMap, we can achieve an average time complexity of O(1) for the put and get operations and space complexity of O(n).
- Total time for insertion of n elements in a HashMap = n * O(1) = O(n)
- Time Complexity: O(1)
- Space Complexity: O(N)
- TreeMap has complexity of O(logN) for insertion and lookup. TreeMap does not allow null key but allow multiple null values
- Total time for insertion of n elements in a TreeMap = Log 1 + Log 2 + Log 3 + ... + Log (n-1) --> (n-1) * Log (n) -->
O(logN)
- Complexity: O(logN)
- It will take O(log N) time to insert and delete each element in the priority queue.
- Based on heap structure, priority queue also has two types max - priority queue and min - priority queue.
- Complexity: O(logN)