Whats the time complexity of this implementation of bubble sort in one loop?


#1
def sort(l):
   n = len(l) - 1
   for i in range(n*n):
      pos = i % n
      if l[pos] > l[pos+1]:
          l[pos], l[pos+1] = l[pos+1], l[pos]

#2

time complexity is O(n^2).


#3

The time complexity is O(n^2).
Since, in 1st run there is two loop running one till n-1 and other till n.
So, n*(n-1)= n^2… Smallest element(n*1) is ignored during time complexity.


#4

time complexity is O(n^2) given the complexity n to the first loop and then to the if statement i.e n^2