Elior Kertsman
Elior Kertsman

Reputation: 44

Does O(1) time complexity equals to O(1^n)

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

Answers (1)

GhostCat
GhostCat

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

Related Questions