The document presents an implementation of the insertion sort algorithm in Python, which sorts a list in-place. The time complexity of the algorithm is O(n²), indicating that its execution time increases quadratically with the size of the input list. The code includes a test case that demonstrates the sorting process and prints the list after each insertion.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
4 views1 page
Insert Sort Algorithm Explained
The document presents an implementation of the insertion sort algorithm in Python, which sorts a list in-place. The time complexity of the algorithm is O(n²), indicating that its execution time increases quadratically with the size of the input list. The code includes a test case that demonstrates the sorting process and prints the list after each insertion.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
# Tempo de execução: c1*n²
def insert_sort(A:list): for i in range (1, len(A)): key = A[i] j = i - 1 while j >= 0 and A[j] > key: A[j+1] = A[j] j -= 1 A[j+1] = key print(A) return A
test = [31,18,33,11,57,15] print(test) insert_sort(test)