Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am using Eclipse application Remember:You can remove all the variables from the workspace by writing clearLook up the description of all the functions in

I am using Eclipse application

Remember:You can remove all the variables from the workspace by writing clearLook up the description of all the functions in MATLABby typing doc in the command window. ImplementlinearSearch(a,key)and binarySearch(a,key)functions .Part A. In this part we will calculate theaverage-case running time of each function. 1.Request the user to enter a positive integer, and call it n.(n = 105) 2.Generate nrandom integersbetween -1000to1000and save them in arraya.(You can use randi function in MATLAB) 3.Sort a(you can use any sorting algorithm you want. If you are using MATLAB, you can call the sortfunctionto sort your numbers) 4.Pick a random numberinaand save it invariable calledkey. 5.Call eachfunction separately to search for the keyin the given array. 6.To calculatethe average-running time, you need to have a timer to save the total runtime when repeating step 4 and 5 for 500 times. (tic toc in MATLAB)(Note1: Do not forget to divide the runtime by the number of the times you run step 4-5) (Note2: Remember to choose a different random number each time you go back to step 4.) Part B. In this part we willcalculate theworst-case running time of each function. 1.Repeat steps 1 to 3inpart A. 2.Now to havethe worst-casescenario, set the value of the key to5000to makesure it does not exist in the array. 3.Run each function once to calculatethe worst-case running time whenn=105. 4.Calculate how much time your machine takes to run onesingle step. (Hint: look at HW3) 5.Now estimatethe worst-case running timeforeach algorithm when n=107.(Hint: look at HW3) 6.Now repeat step 1-3 forn = 107and compare the actual running time with youranswer in step 5.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions

Question

=+19.2. (a) Show that L"((0, 1], , A) is not separable.

Answered: 1 week ago

Question

When should you avoid using exhaust brake select all that apply

Answered: 1 week ago