0% found this document useful (0 votes)
43 views

Output:: Arr Arr I Arr J Arr J Arr J Arr J

The document describes an insertion sort algorithm that sorts an array in place by iterating through the array, comparing each element to its predecessor and swapping elements if they are out of order until the element is in the correct position; it provides an example that prints an unsorted array, runs insertion sort on it, and prints the sorted array.

Uploaded by

Tushar Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Output:: Arr Arr I Arr J Arr J Arr J Arr J

The document describes an insertion sort algorithm that sorts an array in place by iterating through the array, comparing each element to its predecessor and swapping elements if they are out of order until the element is in the correct position; it provides an example that prints an unsorted array, runs insertion sort on it, and prints the sorted array.

Uploaded by

Tushar Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

def 

insertionSort(arr):
    for i in range(1,len(arr)):
        value=arr[i]
        j=i-1
        while j>=0 and value<arr[j]:
            arr[j+1]=arr[j]
            j-=1
            arr[j+1]=value
    return arr

arr=[10,5,13,8,2]
print("Array Before Sorting:", arr)
insertionSort(arr)
print("Array After Sorting:",arr)

Output:

You might also like