Junior — Middle
What is the complexity order of the algorithm for searching a specific element in a list by index?
sobes.tech AI
Answer from AI
In Python, lists are implemented as dynamic arrays, so access to an element by index has a time complexity of O(1). This means that the operation of retrieving an element by index is performed in constant time, regardless of the size of the list.
Example:
lst = [10, 20, 30, 40]
element = lst[2] # Retrieves the element with value 30 in O(1)