Suppose I have a function CalculateOutput(n) which creates an array of size n and repeatedly modifies this array by iterating through every element from 0 to n - 1 (say this is done in linear time). When the array is in a particular order then the number of times the CalculateOutput has walked the array is returned. The thing is that as n increases the output does not necessarily increase (e.g. CalculateOutput(4) = 5 while CalculateOutput(5) = 2). How could I determine the time complexity of this algorithm? Or what other information would I need to be able to determine the running time?
I believe that if there were some other method to determine the number of iterations over the array (call it m) for a given n then it would be that CalculateOutput = O(m * n). But I only know what this m is by running the algorithm previously described.