repl.it
@Mattgwater/

understandingTimeComplexityofPythonListPop

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
list1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
list2 = list1
print(list1[3]) # d
list1.pop(3)
print(list1) # ['a', 'b', 'c', 'e', 'f', 'g', 'h', 'i']
print(list1[3]) # e
print(id(list1) == id(list2)) # True (They're still the same item in memory)
# 9 8 7 6 5 4 3 2 1 = 45 / 9 = 5 
  # 9 operations for removing a (deleting a and then readjusting the other values indices) etc
  # 45 = K * N 
  # 9 = n 
  # kn / n = k so its O(k)

'''
0123
4
5678
'''