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

Let's assume an array has three elements:

 A=[1,2,3]

      

What I want to know is that it is possible to add each element of the array to each other so that the time complexity is O (n) ?. The result should be

b=[(1+1),(1+2),(1+3),(2+2),(2+3),(3+3)]

      

+3


source to share


1 answer


No, it is O(n^2)

.



Now let's see if someone proves to me that I'm wrong ... even better, someone proved my statement correctly - see the comments below.

+5


source







All Articles