Question: Empirically compare the algorithms discussed and presented during lectures. For each of the following sub-problems run each of the algorithms in the pair and record


Empirically compare the algorithms discussed and presented during lectures. For each of the following sub-problems run each of the algorithms in the pair and record the wall clock running time. Do this for multiple ordered input sizes. You need to at least use the input of the following sizes, but may chose to use more sizes: [10,100,1000,10000] For each of the problems generate a single plot that combines the plots of 2 functions: one for each algorithm. X-axis is the size of the problem. Y-axis is the wall-clock time in seconds. (a) Search in a sorted list. Compare the Linear Search and the Binary Search algorithms. \# you may generate a sorted sequence of length n as follows \# seq = [x for x in range (n)] def linear_search(sequence, key): for element in sequence: if element == key: return True return False def binary_search(sequence, start, end, key): if end return False middle = (end + start) //2 if sequence [middle] == key: return True elif sequence[middle] > key: return binary_search(sequence, start, middle - 1, key) else: return binary_search(sequence, middle +1, end, key)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
