What do you learn from these plots

Assignment Help Basic Computer Science
Reference no: EM131215298

In this series of exercises, you will write a script that performs some measurements that justify the need to sort a vector.

Background:

• Since this need is only apparent when processing large amounts of data, we will use a vector of at least 100,000 elements.

• MATLAB has two built-in functions that collectively provide stopwatch capability: tic and toc. The function tic starts the stopwatch, and toc returns the number of seconds since the last tic.

• However, since the time difference is measured to the resolution of milliseconds, we will have to repeat the experiments a number of times to achieve accurate measurements.

• Since this involves a for loop that itself will cost time, we must also measure the overhead of the for loop and subtract that from the computational cost of the operation we are timing.

a. Begin your script by deciding on the vector size, N, and the number of repetitions, reps, and making a vector, vec, of random integers between 0 and N.
b. Write an empty function, junk, that consumes a vector of size N and a number and returns a number.

c. Use tic and toc to compute the time for a for loop that does nothing but pass vec and round(N*rand(1,1)) to junk. Adjust the value of reps until this loop takes about a second to run. Store this cost in the variable overhead.

d. Write a function, linearSearch, that consumes a vector and a number and performs a linear search on the vector looking for that number. It should return either the position of that number in the vector or an empty vector if the number is not present.

e. Add a loop to your script like the loop in step c, except calling linearSearch. Subtract overhead from the computed time and save it as linearSearchTime.

f. Now sort the vector vec using the MATLAB sort(...) function and store it in a new vector, sortedVec.

g. Write the function binarySearch that consumes a vector and a number and uses the algorithm in section 16.1.1 to find the position of the number in the vector returning its position or the empty vector. h. Now, repeat step e, calling your new binarySearch function, saving the time as binarySearchTime.

i. Plot the times of the linear and binary searches for a range of values of N. What do you learn from these plots?

Reference no: EM131215298

Virtual written report and powerpoint presentation

This assignment contains two (2) sections: Written Report and PowerPoint Presentation. You must submit both sections as separate files for the completion of this assignment.

Driving force causing this evolution

Discuss the evolution of client-server computing from file server to multilayer applications to Web-based applications. What has been the driving force causing this evolution?

Draw an isosceles triangle

Using the Point and Line classes described in Section 7.2, see page 78 of attachment draw an isosceles triangle with the following configuration:start = Point(1, 1)finish =

Determine the number of comparisons

Determine the number of comparisons (as a function of n and m) that are performed in merging two ordered files a and b of sizes n and m, respectively, by the merge method pr

Display the positive even numbers

The following code is supposed to display the positive even numbers less than 12. That is, it will output the numbers 2, 4, 6, 8 and 10. However, there is a logical error in

Create class savingsaccount

Create class SavingsAccount. Use a static variable annualInterestRate to store the annual interest rate for all account holders. Each object of the class contains a private

Research and pick one organization

Research and Pick ONE organization that can you conduct a risk assessment on. It can be any organization or company of choice. For the case study, you are pretty much creating

Integral part of learning

Remember that discussions are an integral part of your learning. Expressing and sharing your ideas based on knowledge learned, expands everyone's learning experience. This i

Reviews

Write a Review

 
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd