Yes, this is O(n^2)
, assuming the function executed is O(1)
, of course, and the iterator is also O(1)
on average per iteration (which is usually a valid assumption).
Note that even if you optimize it further, you are going to process Choose(n,2)
elements, and Choose(n,2)=n(n-1)/2
, which is still in O(n^2)
.