Question: Python 3.6 - This is a code for doing selection sort and merge sort. I'm having a hard time following the code. Please explain the

Python 3.6 - This is a code for doing selection sort and merge sort. I'm having a hard time following the code. Please explain the code with block comments step by step. Thanks

import time import random randfile = open("Random.txt", "w") start = int(input('Enter lower limit of random numbers: ')) end = int(input('Enter upper limit of random numbers: ')) for i in range(int(input('How many to generate?: '))): line = str(random.randint(start, end)) randfile.write(line + ' ') print(line) randfile.close() # example of selection sort algorithm : needs modification def swap(a, i, j): (a[i], a[j]) = (a[j], a[i]) def selectionSort(a): n = len(a) for startIndex in range(n): minIndex = startIndex for ind in range(startIndex+1, n): if a[ind] < a[minIndex]: minIndex = ind swap(a, startIndex, minIndex) lst = [] with open("Random.txt", "r") as f: for line in f: lst.append(int(line.strip())) start_time = time.time() selectionSort(lst) end_time = time.time() file = open("selectionSortResult","w") for x in lst: file.write(str(x)+" ") file.close() print('Sorted Selection Sort List: ', lst) print('Elapsed time for Selection Sort: {:.20f} seconds'.format(end_time-start_time)) def merge_sort(A): """ Sort list A into order, and return result. """ n = len(A) if n==1: return A mid = n//2 # floor division L = merge_sort(A[:mid]) R = merge_sort(A[mid:]) return merge(L,R) def merge(L,R): """ Given two sorted sequences L and R, return their merge. """ i = 0 j = 0 answer = [] while i                                            

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!