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

16 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Mar 02 '25

This shows: time (and space) complexity in Big-O notation describes how an algorithm scales as input size increases, rather than how well it performs for a specific input size.

Yeah that's what I totally missed.