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.
Loading...
Related Quiz
- The ____ method in the unittest framework is used to compare whether two values are equal.
- The ____ function in Pandas is used to load a dataset from a CSV file into a DataFrame.
- You need to develop a recurrent neural network (RNN) to analyze sequential data. How would you implement this using TensorFlow or PyTorch?
- How would you implement rate limiting in a RESTful API to prevent abuse?
- You are required to implement a Python loop that needs to perform an action after every iteration, regardless of whether the loop encountered a continue statement during its iteration. Which control structure would you use?