Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started