Question: Write a program that has both Linear Search and Binary Search algorithms implemented defined as two seprate functions. Run each of the algorithms on the
Write a program that has both Linear Search and Binary Search algorithms implemented defined as two seprate functions. Run each of the algorithms on the list of integers from 0 to 999999 and time them on three different numbers to search for: 10, 499999, and 999999. At the end your program should print the results. (Python)
So far this what I have for the answer:
# This programs has implementation of two algorithms: # linear search and binary search ... from time import time def main(): numbers = list(range(1000000)) # generate a list of numbers from 0 to 999999 #print(numbers) start = time() linear_search(numbers,10) end = time() print the resulting time with comments start = time() linear_search(numbers,499999) end = time() print the resulting time with comments start = time() linear_search(numbers,999999) end = time() print the resulting time with comments do the same for binary search def linear_search(items,target): """ add the specification here """ ....... return index or return -1 def binary search(items,target): """ add the specification here """ ..... return index or return -1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
