Possible Duplicates:
Program/algorithm to find the time complexity of any given program.
Programmatically obtaining Big-O efficiency of code
Hi, i am eager to develop a function(say computeComplexity()
) which can determine the time complexity and space complexity of any algorithm(say bubbleSort()
).
Usage of computeComplexity() function can be as below.
void bubbleSort()
{
computeComplexity();//Start monitoring memory consumption and time spent.
....
.... //Sorting algorithm goes here
....
computeComplexity();//Display time complexity and space complexity
}
Output would look like
Algorithm ran : Bubble sort
Time complexity: O(n^2)
Space complexity: O(n^2)
I am yet to try any approach for this.
I thought, its better to check with experts here first.