Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add all elements with each other in array in O(n) time

Suppose an array consist of 3 elements:

 A=[1,2,3]

What I want to know is that, is it possible to add each element of array with each other such that time complexity is O(n)?. Result should have

b=[(1+1),(1+2),(1+3),(2+2),(2+3),(3+3)]
like image 799
user2137186 Avatar asked Dec 08 '25 19:12

user2137186


1 Answers

No, that's O(n^2).

Now let's see someone prove me wrong ... even better, someone has proven my assertion right -- see the comments below.

like image 76
High Performance Mark Avatar answered Dec 10 '25 15:12

High Performance Mark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!