Question: Hello, I need a linear search function added to this code including the running time for this function. This code is taken from chegg. (python)
Hello, I need a linear search function added to this code including the running time for this function. This code is taken from chegg. (python)
import timeit """ Selection sort function which sorts using given parameter index """ def selection_sort(records, ind): n = len(records) for i in range(n): min = i for j in range(i+1,n,1): if records[j][ind] < records[min][ind] : min = j records[i], records[min] = records[min], records[i] """ Insertion sort function which sorts using given parameter index """ def insertion_sort(records, ind): n = len(records) for i in range(1, n, 1): j = i-1 key = records[i][ind] while j>=0 and records[j][ind] >key : records[j+1][ind] = records[j][ind] j -= 1 records[j+1][ind] = key """ Bubble sort function which sorts using given parameter index """ def bubble_sort(records, ind): n = len(records) for i in range(n): swapped = False for j in range(0,n-i-1,1): if records[j][ind] > records[j+1][ind] : records[j][ind] , records[j+1][ind] = records[j+1][ind], records[j][ind] swapped = True if not swapped : break """ Merge function to help MergeSort """ def merge(records, low, mid, high, ind): left_arr = records[low:mid+1] right_arr = records[mid+1:high+1] i=0 j=0 for k in range(low,high+1,1): if left_arr[i][ind] <= right_arr[j][ind]: records[k] = left_arr[i] i+=1 else: records[k] = right_arr[j] j+=1 if(i == len(left_arr)): for temp in range(k+1, high+1, 1): records[temp] = right_arr[j] j += 1 break elif(j == len(right_arr)): for temp in range(k+1, high+1, 1): records[temp] = left_arr[i] i += 1 break """ Merge sort function which sorts using given parameter index """ def merge_sort(records ,low, high, ind): if lowplease use this data for student_data.txt file, this represents the student id, first name, last name, email, and major for 20 students.
1,742,abc,def,abc@gml.com,physics
2,460,jkl,nfs,jkl@gml.com,biology
3,304,bla,rav,bla@gml.com,cse
4,120,utz,ajf,utz@gml.com,math
5,052,bwk,ydm,bwk@gml.com,chemistry
6,104,rlz,gia,rlz@gml.com,eee
7,052,gpa,alr,gpa@gml.com,physics
8,469,slz,gra,slz@gml.com,math
9,350,mad,raf,mad@gml.com,biology
10,018,fla,rgi,fla@gml.com,cse
11,502,oga,emz,oga@gml.com,math
12,311,pra,doz,pra@gml.com,eee
13,451,pea,zue,pea@gml.com,ist
14,014,brl,urx,brl@gml.com,economics
15,183,pgs,tha,pgs@gml.com,finance
16,401,uah,bha,uah@gml.com,physics
17,362,pts,gys,pts@gml.com,math
18,272,gps,hgs,gps@gml.com,economics
19,528,xhy,pjs,xhy@gml.com,biology
20,254,mea,sfu,mea@gml.com,physics
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
