Big O notation for complexity of a program
조회 수: 5 (최근 30일)
이전 댓글 표시
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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!