Reputation: 44
I know the definitions of both of them, but can i ignore from the O(1^n) or it's different?
Thanks.
Upvotes: 0
Views: 96
Reputation: 140573
O(1)
means: it takes constant time to "do that thing", independent of any n you are processing.
And 1^n
computes to 1
, too. Because 1^n
is 1*1*1..
n times.
Maybe, maybe, if you were instead thinking about:
1 + 1 + 1 + 1 ... n times
Here you end up with O(n)
( 1*1*... isn't the same as 1+1+1... )
The difference is essentially: as long as the execution time is constant, no matter how many "things" get processed, then you are O(1)
. As soon as that number n somehow comes into play, you are not.
Upvotes: 4