Python lists are implemented as dynamic arrays, which affects the time complexity of insertion and deletion operations.
append() – Add at the Endmy_list.append(10) # Adds element at the end
insert(index, value) – Insert at a Specific Positionmy_list.insert(2, 50) # Inserts 50 at index 2
pop() – Remove from the Endmy_list.pop() # Removes the last element
pop(index) – Remove from a Specific Positionmy_list.pop(2) # Removes element at index 2
remove(value) – Remove by Valuemy_list.remove(50) # Removes first occurrence of 50
O(n)) and then removes it (O(n), worst case).| Operation | Method | Time Complexity |
|---|---|---|
| Insert at End | append() |
O(1) (Amortized) |
| Insert at Middle | insert(i, x) |
O(n) |
| Delete at End | pop() |
O(1) |
| Delete at Middle | pop(i) |
O(n) |
| Delete by Value | remove(x) |
O(n) |