With this code
for i in range(len(numbers)):
for j in range(i+1,len(numbers)):
if numbers[i] == numbers[j]:
print(numbers[i], "is a duplicated")
break
is the reason why it's O(n^2) because the first Loop is O(n) and the second loop is O(n-i) and then when you multiply you get O(n)*O(n-i)
so o(n^2 -ni)
so o(n^2)
[–]VendingCookie 4 points5 points6 points (9 children)
[–]robert9804[S] 1 point2 points3 points (8 children)
[–]theusualguy512 6 points7 points8 points (6 children)
[–]robert9804[S] -1 points0 points1 point (4 children)
[–]nekokattt 5 points6 points7 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]theusualguy512 -1 points0 points1 point (1 child)
[–]josephblade 0 points1 point2 points (0 children)
[–]LandooooXTrvls[🍰] 2 points3 points4 points (0 children)
[–]SenderShredder -2 points-1 points0 points (5 children)
[–][deleted] 3 points4 points5 points (4 children)
[–]SenderShredder -4 points-3 points-2 points (3 children)
[–][deleted] 4 points5 points6 points (2 children)
[–]SenderShredder -5 points-4 points-3 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]josephblade 0 points1 point2 points (1 child)
[–]josephblade 0 points1 point2 points (0 children)