Answer the question
In order to leave comments, you need to log in
How to reduce the complexity of the algorithm?
Good evening, please explain I just started learning python, there is a list, it needs to be sorted in ascending order without sort() or sorted(). I made up the code, but its complexity is O(n**2). Is it possible to simplify my algorithm?
a = list(map(int, input().split()))
n = 0
while n < len(a):
for i in range(1, len(a)):
if a[i - 1] > a[i]:
a[i - 1], a[i] = a[i], a[i - 1]
n += 1
print(a)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question