Is O((b-a)/c) the time complexity of list[a:b:c] in python3?
Question:
According to https://wiki.python.org/moin/TimeComplexity, the complexity of "Get a Slice" from list is O(k) and k is the length of wanted slice.
If there is a step parameter, the complexity will become O(k/step)? (i.e. O((b-a)/c) for list[a:b:c])
Answers:
Surely it is. Getting a value from a list via its index, is O(1). Getting k items from a list via their indexes, is O(k). No matter you are getting them with steps or getting them without steps or even without slices:
l = list(range(10))
l1 = l[1:6:2]
l2 = [l[1], l[3], l[5]]
l3 = [l[i] for i in range(1,6,2)]
They are all O(number of elements)
According to https://wiki.python.org/moin/TimeComplexity, the complexity of "Get a Slice" from list is O(k) and k is the length of wanted slice.
If there is a step parameter, the complexity will become O(k/step)? (i.e. O((b-a)/c) for list[a:b:c])
Surely it is. Getting a value from a list via its index, is O(1). Getting k items from a list via their indexes, is O(k). No matter you are getting them with steps or getting them without steps or even without slices:
l = list(range(10))
l1 = l[1:6:2]
l2 = [l[1], l[3], l[5]]
l3 = [l[i] for i in range(1,6,2)]
They are all O(number of elements)