tags:

views:

111

answers:

2

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.

A: 

The main problem is probably that different algorithms require completely different input. You might be able to write a function that classifies the performance of sorting functions since they all use the same type of input, and you can just generate an increasingly larger set to see how performance degrades.

Emil H
A: 

You might be able to write something that can compare complexities on one machine, but as soon as you put your script on another machine things are going to get very confusing. You'd have to figure out some way of calibrating it, and even then it would only work on "perfect" algorithms.

fredley