What is the time complexity of accessing an element at a specific index in an array?
Accessing an element at a specific index in an array takes O(1) time because arrays allow direct access using the index.
Click to reveal answer
beginner
How do you update the value at index 3 in an array named arr to 10 in Python?
You update the value by assigning the new value directly: arr[3] = 10
Click to reveal answer
beginner
What happens if you try to access an index that is out of the array's range?
Accessing an index outside the array's range causes an IndexError in Python, meaning the index is invalid.
Click to reveal answer
intermediate
Explain why arrays are good for fast access but not always for fast insertion or deletion.
Arrays allow fast access because elements are stored contiguously and can be accessed by index directly. But insertion or deletion in the middle requires shifting elements, which takes O(n) time.
Click to reveal answer
beginner
Show the Python code to access and update the 2nd element of an array arr and print the updated array.