0% found this document useful (0 votes)
44 views2 pages

Research

The document describes sorting student percentage scores stored in an array using insertion sort and shell sort. It provides pseudo code for insertion sort and shell sort algorithms. The input is the size of the array and elements. It explains the sorting techniques briefly and provides sample code to sort an example array using both algorithms and print the top five scores.

Uploaded by

prembisuit2021
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)
44 views2 pages

Research

The document describes sorting student percentage scores stored in an array using insertion sort and shell sort. It provides pseudo code for insertion sort and shell sort algorithms. The input is the size of the array and elements. It explains the sorting techniques briefly and provides sample code to sort an example array using both algorithms and print the top five scores.

Uploaded by

prembisuit2021
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/ 2

Practical No: 5 (B)

Practical Title: Sorting of an array using insertion and shell sort


Aim: Write a Python program to store second year percentage of students in
array. Write function for sorting array of floating point numbers in ascending
order using
a) Insertion sort
b) Shell Sort and display top five scores
Pre-requisite:
Knowledge of sorting techniques
Objective:
 To sort array of floating point numbers in ascending order using
a)Insertion Sort b)Shell sort and display top five scores.
 Sorted list of elements
 Top five scores.
Input:
Size of array Elements of array
Theory:
- Write short theory of sorting. - Explain insertion and shell sort with example
Algorithm:
def selection Sort(alist):
for fill slot in range(len(alist)-1,0,-1):
position Of Max=0
for location in range(1,fillslot+1):
if alist[location]>alist[position OfMax]:
position Of Max = location
temp = alist[fillslot]
alist[fillslot] = alist[position Of Max]
alist[position Of Max] = temp
alist = [54,26,93,17,77,31,44,55,20]
selectionSort(alist)
print(alist)

def shellSort(alist):

sublistcount = len(alist)//2

while sublistcount > 0:

for start position in range(sublistcount): gap

Insertion Sort(alist,startposition, sublistcount)

print("After increments of size",sublistcount,"The list is",alist)


sublistcount = sublistcount // 2

def gapInsertionSort(alist,start,gap):

for i in range(start+gap,len(alist),gap):

currentvalue = alist[i]

position = i

while position>=gap and alist[position-gap]>currentvalue:

alist[position]=alist[position-gap]

position = position-gap

alist[position]=currentvalue

alist = [54,26,93,17,77,31,44,55,20]

shellSort(alist)

print(alist)

Flowchart:

Draw flowchart for above algorithms

Conclusion:

By this way, we can sort percentage of students in array using insertion sort and
shell sort.

Question Bank:

1. Explain the sorting?

2. What are the different types of sorts in data structures?

3. How many passes are required in insertion and shell sort?

4. What is the time complexity of insertion and shell sort?

You might also like