edited by
605 views
1 1 vote

I always thought the complexity of:

1 + 2 + 3 + ... + n is O(n), and summing two n by n matrices would be O(n^2).

But today I read from a textbook, "by the formula for the sum of the first n integers, this is n(n+1)/2" and then thus: (1/2)n^2 + (1/2)n, and thus O(n^2).

What am I missing here?

1 Answer

0 0 votes

actually if someone ask TC of value produced by sum of n natural numbers then TC=O(n2)

if asked TC of the computation to produce this sum then TC=O(n)


it's just like TC of multiplication for factorial n (n!) is O(n)

while TC of value produced is O(nn)

Position:
Show:

Related questions

0 0 votes
1 answers 1 answer
781
781 views
0 0 votes
3 3 answers
817
817 views
GO Classes asked Jul 3, 2025
817 views
Which of the following are self-complemented codes?A. Excess-$3$ (XS-$3$) CodeB. $2421$ CodeC. $8421$ (BCD) CodeD. $84-2-1$ Code
1 1 vote
0 0 answers
775
775 views
shashank023 asked Jul 16, 2017
775 views
I have to solve the queries using tuple relational calculus and I just want to know if I did them correctly. I'm using this database:EMPLOYEE: fname , minit , lname, ssn ...