What is the time complexity of accessing an element in a Python list by index?

  • O(1)
  • O(log n)
  • O(n log n)
  • O(n)
Accessing an element in a Python list by index has a time complexity of O(1). Lists are implemented as arrays, and accessing an element by index can be done in constant time because the index directly maps to a memory location.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *