Documentation: Complexity of array assignment in Source §3,4
Closed this issue · 0 comments
martin-henz commented
We should make sure that we point out that array assignment in JavaScript is not O(1). Instead, we can only say that it's O(n) where n is the index.
const a = [];
a[1000000] = 0;
This does not necessarily run in constant time. Our explanation should be consistent with the fundamental property that time complexity is always greater or equal than space complexity, under the assumption that the input data is included in the space complexity and the time it takes to construct the input data is included in the time complexity.