Big O notation for complexity of a program

6 vues (au cours des 30 derniers jours)
Hazim Nasir
Hazim Nasir le 19 Avr 2020
Commenté : Hazim Nasir le 20 Avr 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
  2 commentaires
Tommy
Tommy le 19 Avr 2020
Hazim Nasir
Hazim Nasir le 20 Avr 2020
Thank you very much

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by