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

Questions Cloud

Proper relationship between science and religion : 1) According to Galileo, what are his enemies motives and why do they use religious arguments against him? 2) According to Galileo, why is it dangerous to apply passages of Scripture to science? 3) To Galileo, how does nature differ from the Bible as..
Main purpose of marriage : 1. According to the speaker Lionardo, what discourages young men from marrying? 2. What is the main purpose of marriage, according to the characters in the dialogue? 3. In arranging marriages, how much input did the future wife and husband have?
Find the conditional pdf : Suppose a pair of random variables  (X,Y) uniformly distributed over a rectangular region - Find the conditional PDF (X,Y).
Concerning the new england restraining act : Which of the following statements is not true concerning the New England Restraining Act? A. It banned New England's commerce with the British West Indies
What do you learn from these plots : 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.
Tributaries of the ohio-mississippi river system : Until about 1830, most western settlers were southerners who settled near the tributaries of the Ohio-Mississippi River system. True or False?
Conduct the correct test of hypothesis : A local school board wanted to compare test scores on standardized mathematics tests for 9th grade students in 2 different junior high schools. Conduct the correct test of hypothesis
Identify a local non-profit organization : Identify a local Non-Profit Organization. What social problem does the non-profit organization solve? Describe the scope of the problem solved.
Culture political system : How did Egypt's physical location along the Nile River affect the culture's political system,religion, and art? Explore at least three examples.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Calculate height and velocity of balloon

The calculation of height and velocity should be done in a single function that will accept the time, calculate the height and velocity of the balloon and send both the height and velocity back to the function call.

  Two main functions of user accounts in a network

What are the two main functions of user accounts in a network?

  Hat mechanism would you implement in the process

what mechanism would you implement in the process scheduler to automate the termination of a job thats in an infinite loop? take into account jobs that legitimately use large amounts of CPU time, for example, one "finding the first 10,000 prime nu..

  Find the minimum mips instruction to perform

1)    Find the minimum MIPS instruction to perform the following C statements. Use any registers for variables. Assume that the base register for array Y is in $s0.

  Use the encase software or digital forensics framework

Compare and contrast systems forensic uses of the military, law enforcement agencies, and private corporations. Determine which of these groups has the greatest need for systems forensics and what issues may arise if adequate forensics operations ..

  Write a function n=countequal(g,t) that duplicates

Simulate the testing of 100 microprocessors as described in Example 1.43. Your output should be a 4 × 1 vector X such that Xi is the number of grade i microprocessors.

  Cost per server

cost per server

  Modify dijkstra''s algorithm

a. Explain how to modify Dijkstra's algorithm to produce a count of the number of different minimum paths from v to w. b. Explain how to modify Dijkstra's algorithm so that if there is more than one minimum path from v to w, a path with the fewest nu..

  Create a function that totals jan through dec sales

Formulas & Functions-In this section you will assist sales manager in categorizing company's revenue sources and how each one relates to each other. Create a function that totals Jan through Dec sales for Online Reservations.

  Expected interest rates to rise

What would be the preferred strategy for a borrower paying interest on a future date if he expected interest rates to rise?

  Determine whether jump instructions are necessary to execute

Given a straight-line program for a Boolean function, describe the steps taken to compute it during fetch-and-execute cycles of a RAM. Determine whether jump instructions are necessary to execute such programs.

  Security layers-protecting the system

Analyze the seven security domains of a typical IT infrastructure and determine which two of the seven you would implement first for a nationwide bank. Explain your rationale for your choice.

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