#program to compare the time taken to sort n random numbers using a bubble sort # an insertion sort and a merge sort import random import time #insertion sort def insertionSort(alist,n): for j in range(1,n): nextnum = alist[j] #insert nextnum into the sorted sequence numbers1[1..j-1] i = j - 1 while i>=0 and alist[i]>nextnum: alist[i + 1] = alist[i] i = i - 1 alist[i + 1] = nextnum #bubble sort def bubbleSort(alist,n): m = n while m>1: for count in range (0, m - 1): if alist[count] > alist[count + 1]: temp = alist[count] alist[count] = alist[count+1] alist[count+1] = temp m = m - 1 def mergeSort(alist): # print("Splitting ",alist) if len(alist)>1: mid = len(alist)//2 lefthalf = alist[:mid] righthalf = alist[mid:] mergeSort(lefthalf) mergeSort(righthalf) i=0 j=0 k=0 while i