Half of the integers stored in the array data are positive a

Half of the integers stored in the array data are positive, and half are negative. Determine the

Absolute speed of the following algorithm, assuming; the time to execute a memory access is

100 nanoseconds and that all other operations (arithmetic, register access, etc0 take 10 nanoseconds

for (int i= 0; i<1000000;i++)

{ if (data[i] <0)

                Data [i] = data [i] *2;

}

Solution

Arthimetic operations:

i++ 10nanoseconds *(1000000)

data[i] * 2 10nanoseconds * (500000)

Memory access:

data[i] <0 100 nanoseconds *(1000000)

Data[i]=data[i]*2 100nanoseconds *(500000)

Other operations:

i<1000000 10 nanoseconds * (1000000+1)

i=0 10 nanoseconds *(1)

Total=10000000+5000000+100000000+50000000+100000010+10

=265000020 nanoseconds

Half of the integers stored in the array data are positive, and half are negative. Determine the Absolute speed of the following algorithm, assuming; the time t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site