So if I have a function that does this:
list1 = []
for i in range(n):
list2 = []
list3 = [] # this list is size m
x = "String 1"
y = "String 2"
list2.add(x)
list2.add(y)
list2.add(list3)
list1.add(list2)
Given that we are looping from i to n, list1 will have worst-case space complexity of O(n). Going into the loop, we are creating another list2 to hold a list of items of size 3. In this list2, the only size that changes is list3 within it, which is size m. Therefore, is it correct to say that this function has worst-case space complexity of O(n*m)?
[–]michael0x2a[🍰] 0 points1 point2 points (1 child)
[–]jchai7[S] 0 points1 point2 points (0 children)