Notation | Name |
---|---|
O(1) | Constant |
O(logn) | Logarithmic |
O(n) | Linear |
O(nlogn) | n log-star n |
O(n^2) | Quadratic |
Operation | Time Complexity |
---|---|
Retrieve with index. | O(1) - Constant time |
Retrieve without index. | O(n) - Linear time |
Add an element to full array. | O(n) - Linear time |
Add an element to the end of an array. (has space) | O(1) - Constant time |
Insert or update an element at a specific index. | O(1) - Constant time |
Delete an element by setting it to null. | O(1) - Constant time |
Delete an element by shifting elements. | O(n) - Linear time |
Performance | Time Complexity |
---|---|
Worst Case | O(n^2) - Quadratic time |
Avarage Case | O(n^2) - Quadratic time |
Best Case | O(n) - Linear time |
Performance | Time Complexity |
---|---|
Worst Case | O(n^2) - Quadratic time |
Avarage Case | O(n^2) - Quadratic time |
Best Case | O(n^2) - Quadratic time |
Performance | Time Complexity |
---|---|
Worst Case | O(n^2) - Quadratic time |
Avarage Case | O(n^2) - Quadratic time |
Best Case | O(n) - Linear time |
Performance | Time Complexity |
---|---|
Worst Case | O(n^2) - Quadratic time |
Avarage Case | O(nlogn) - n log-star n |
Best Case | O(nlogn) - n log-star n |
Performance | Time Complexity |
---|---|
Worst Case | O(nlogn) - n log-star n |
Avarage Case | O(nlogn) - n log-star n |
Best Case | O(nlogn) - n log-star n |
Performance | Time Complexity |
---|---|
Worst Case | O(n^2) - Quadratic time |
Avarage Case | O(nlogn) - n log-star n |
Best Case | O(nlogn) - n log-star n |
Performance | Time Complexity |
---|---|
Worst Case | O(n+k) |
Avarage Case | O(n+k) |
Best Case | O(n+k) |
Performance | Time Complexity |
---|---|
Worst Case | O(kn) |
Avarage Case | O(kn) |
Best Case | O(kn) |
Operation | Time Complexity |
---|---|
Insert at last index | O(1) --> If array copy operation is Considered then O(n) |
Insert at given index | O(n) |
Search by value | O(n) ( Preferred ) |
Get by index | O(1) ( Preferred ) |
Remove by value | O(n) |
Remove by index | O(n) |
ArrayList<Employee> employees = new ArrayList<>();
Operation | Time Complexity |
---|---|
Insert at last index | O(1) ( Preferred ) |
Insert at given index | O(n) ( Preferred ) |
Search by value | O(n) |
Get by index | O(n) |
Remove by value | O(n) ( Preferred ) |
Remove by index | O(n) ( Preferred ) |
LinkedList<Employee> employees= new LinkedList<>();
Vector : Unlike the new collection implementations, Vector is synchronized. If a thread-safe implementation is not needed, it is recommended to use ArrayList in place of Vector.
Performance: ArrayList is faster, since it is non-synchronized, while vector operations give slower performance since they are synchronized (thread-safe).
Vector<Employee> employees = new Vector<>();
LIFO (Last-in-first-out)
Operation | Time Complexity |
---|---|
Push | O(n) |
Pop | O(1) |
Peek | O(1) |
Operation | Time Complexity |
---|---|
Push | O(1) |
Pop | O(1) |
Peek | O(1) |
Operation | Time Complexity |
---|---|
Search | O(n) |
Operation | Time Complexity |
---|---|
Search | O(logn) |
FIFO (First-in-first-out)
Operation | Time Complexity |
---|---|
Add | O(1) |
Remove | O(n) |
Peek | O(1) |
Operation | Time Complexity |
---|---|
Add | O(1) |
Remove | O(1) |
Peek | O(1) |
Operation | Time Complexity |
---|---|
Insertion | O(logn) |
Deletion | O(logn) |
Retrieval | O(logn) |