What is the space complexity of an array of size ‘n’ ?
2025
What is the space complexity of an array of size ‘n’ ?
- A.
O(1)
- B.
O(n)
- C.
O(n2)
- D.
O(log n)
Attempted by 237 students.
Show answer & explanation
Correct answer: B
The space complexity of an array of size 'n' is O(n) because the memory required grows linearly with the number of elements. Each element in an array occupies a fixed amount of memory (e.g., 4 bytes for an integer), so storing 'n' elements requires a total space proportional to n. This linear relationship means that as the input size increases, the memory usage scales directly with it.",