Big O notation for complexity of a program

3 Ansichten (letzte 30 Tage)
Hazim Nasir
Hazim Nasir am 19 Apr. 2020
Kommentiert: Hazim Nasir am 20 Apr. 2020
Hello,
I am writing a paper and have written a program where I have to calculate the time complexity for it. the program has to find the summation of a vector of elements
v=sum(x) where x=[x1^2,x2^,…….,x(n^2)]; where n could be 1,10,100,1000,10000. each element has random value. I have used (tic toc) to find the calculation time but I got strange results; I expect that the time will be increase linearly while changing n from 1 to 10000 but I got graphs as shown in the attachment where results differ for each run. I would like to ask: is the time of summation process varies with respect to the values; for example sum[1.2^+2.3^] is differ from sum[11546.233665^2+9866.89^2] ?
Also, I have did the following test:
d=1000;
VarMin = -10;
VarMax = 10;
VarSize=[1 d];
x=unifrnd(VarMin,VarMax,VarSize);
tic
sum(x);
toc
disp('%%%%%%%%%%%%%%%%%%%5')
tic
sum(x);
toc
the results is:
Elapsed time is 0.000100 seconds.
%%%%%%%%%%%%%%%%%%%5
Elapsed time is 0.000056 seconds.
So what is the best way is this case to find the compelxity. Thank you in advance
Hazim

Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by