r/AskComputerScience • • Mar 02 '25
Can algorithmic analysis sometimes be misleading ?
Here are some examples in golang. To be honest these are pretty dumb, but just for argument sake.
Program 1: Initializes an array of length 10, each element set to 1
func main() {
arr := [10]int{}
for i := 0; i < 10; i++ {
arr[i] = 1
}
}
Program 2: Initializes an array of length 1 trillion, each element set to 1
func main() {
arr := [1000000000000]int{}
for i := 0; i < 1000000000000; i++ {
arr[i] = 1
}
}
Aren't both both programs O(1) time and space complexity ? Yet program 2 will use way more RAM than program 1.
To be clear, I'm not arguing complexity analysis is pointless. Just trying to understand analysis from both a theoertical and practical perspective.
0
Upvotes
View all comments
Show parent comment
3
u/Dornith Mar 03 '25
You say that both programs are O(1), but that doesn't make any sense. What is N in this context?
There is no input to these programs, so there's no way to analyze how the behavior changes as the input grows. The Big-O in this context is undefined.