开发者

running time code in O-notation

I want to know how can I calculate running time in O_开发者_开发百科notation in C++ programs? Is there any code for that?

I have to use this code for showing the running time

clock_t start, end;
start = clock();
//CODES GOES HERE

end = clock();

std::cout << end - start << "\n";
std::cout << (double) (end-start) / CLOCKS_PER_SEC;

But I want to calculated it in O_notation code to implement it in 2 programs min-heap and prim's algorithm with array.


Assuming you have well-defined formats for input and output, you stand a reasonable chance of running the code in question for various sizes of input, and doing (for example) a polynomial curve fit to the times take for the various sizes.

So, for example, you'd run the code for 10, 100, 1000, and 10000 inputs. If the run-time gets roughly 10 times as long with each change, you appear to have a linear algorithm. If it gets roughly 100 times as long each time, you appear to have a quadratic one, and so on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜