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

fds5

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

fds5

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

NAME:Sanika S Kulkarni

SE DIV:B ROLL NO 26534

ASSIGNMENT 5

CODE:

def insertionsort(l1):

n = len(l1)

for i in range(1, n):

key = l1[i]

j = i-1

while (j >= 0 and key < l1[j]):

l1[j+1] = l1[j]

j -= 1

l1[j+1] = key

l1 = [99,23,45,56,67.5,23,45,78,67,34]

print("The array before applying insertion sort was ",l1)

insertionsort(l1)

print("The array after applying insertion sort is :",(l1))

OUTPUT:

The array before applying insertion sort was [99, 23, 45, 56, 67.5, 23,
45, 78, 67, 34]
The array after applying insertion sort is : [23, 23, 34, 45, 45, 56, 67,
67.5, 78, 99]

CODE:

def shellsort(l1, n):

gap = n // 2

while (gap > 0):

for i in range(gap, n):


temp = l1[i]

j=i

while (j >= gap and l1[j -gap] > temp):

l1[j] = l1[j - gap]

j -= gap

l1[j] = temp

gap //= 2

l1 = [90.3, 81.4, 30.5, 70, 53, 65, 42, 100,90,40]

print("Array before sorting:",l1)

n = len(l1)

shellsort(l1, n)

print('array after applying shell sort :',l1)

l1.sort(reverse=True)

print(l1)

l2=[]

for i in range (0,5):

l2.append(l1[i])

print("The top 5 scores are :",l2)

OUTPUT:

Array before sorting: [90.3, 81.4, 30.5, 70, 53, 65, 42, 100, 90, 40]
array after applying shell sort : [30.5, 40, 42, 53, 65, 70, 81.4, 90, 90.3,
100]
[100, 90.3, 90, 81.4, 70, 65, 53, 42, 40, 30.5]
The top 5 scores are : [100, 90.3, 90, 81.4, 70]

You might also like