Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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?

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91971281

Have any Question?


Related Questions in Computer Engineering

What are the 5 classic components of a computer discussed

What are the 5 classic components of a computer discussed in class?

Any help will be appreciatedscenarionbspyou are a

Any help will be appreciated Scenario: You are a networking and communications consultant working for HoustonComm Services, Inc, further referred to as HCS. HCS is a company providing technology consulting services to st ...

Identify at least two 2 factors that have led to the

Identify at least two (2) factors that have led to the explosive growth of digital crime over the past a few decades. Next, describe the most common forms of digital crime, and give your opinion as to why those forms you ...

Tests can determine with some degree of accuracy whether a

Tests can determine, with some degree of accuracy, whether a subject indeed has the disease for which s/he is being tested. For instance, a new screening procedure for heart disease was tested on 100 patients with heart ...

Many high school students take the ap tests in different

Many high school students take the AP tests in different subject areas. In 2007, of the 144,796 students who took the biology exam 84,199 of them were female. In that same year, of the 211,693 students who took the calcu ...

1 market equilibrium and deadweight lossa suppose that the

1. Market Equilibrium and Deadweight Loss a) Suppose that the supply and demand for apples are as follows: QD = 100 - 3P QS = 50 + 2P The government now levies a $5 per unit tax on producers. Draw the supply and demand c ...

A string in c is simply an array of characters with the

A string in C++ is simply an array of characters with the null character(\0) used to mark the end of the string. C++ provides a set of string handling function in as well as I/O functions in . With the addition of the ST ...

Jason who is very knowledgeable regarding computers agrees

Jason, who is very knowledgeable regarding computers, agrees to purchase computers for Nick's business. Jason is retained for that purpose only, he is paid a set rate for the job, and Nick exercised no control over the m ...

Question research parallel computing and prepare an

Question : Research parallel computing and prepare an informal paper 2 -3 pages in length, single spaced with a blank line beltween paragraphs. The response must be typed, single spaced, must be in times new roman font ( ...

Using a telephone survey of 400 randomly selected

Using a telephone survey of 400 randomly selected registered voters, he solicits both their party identification and whether or not they had read the newspaper that day. The results are displayed in the following cross-t ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As