# Calculating Big O if unknown runtime of called functions

I haven't been able to track down if there is a generally accepted practice for assigning a Big O value when dealing with functions of unknown runtime.

Given the following pseudocode, with two functions that operate in an unknown time, is it typical to assume the processing is constant time, or would it be more correct to mention them as possible bounds?

function under_evaluation(n)
int sum = 0;
for (int x=0; x<n; x++) {
sum = sum + mathFunction1(x);
}
other_value = mathFunction2(n);
return sum + other_value;
}


So would the best answer for the Big O of function under_evaluation be

• O(n)
• O(n*O(mathFunction1))
• O(nO(mathFunction1)) unless O(mathFunction2)>O(nO(mathFunction1)) in which case O(mathFunction2)

It depends on the situation. Sometimes we treat function calls as "oracle calls", and then we just count oracle calls. Your function makes $$n$$ oracle calls to the first function, and one oracle call to the second function.

Another option is to denote the running time of the first function by $$T_1(n)$$ and that of the second function by $$T_2(n)$$. Assuming that $$T_1(n)$$ is monotone, this will give $$O(nT_1(n) + T_2(n))$$. If you don't want to assume that $$T_1(n)$$ is monotone, then you need to define $$T_1(n)$$ as the maximum running time of the first function on an input which is at most $$n$$.

The mathFunction1 and mathFunction2 must not be unknown. Either

1. no known algorithm exists for one or both of them (and it is incumbent on you to provide at least a strawman feeble/naïve attempt at that algorithm) or
2. one or more algorithms exist for both of them.

If the latter situation, then inventory all (not-unreasonable) known algorithms for each of mathFunction1 and mathFunction2, then obtain what a scientific paper for the lowest-asymptotic growth algorithm states is its big-O growth. (Or if for some reason that algorithm is unsuitable [e.g., has good asymptotic time growth but unacceptable asymptotic space growth], then obtain what a scientific paper for the 2nd-lowest-asymptotic growth algorithm states as its big-O growth.) Then compute your problem algorithm's big-O by utilizing the obtained big-O for both mathFunction1 and mathFunction2, then draw attention to the fact that additional work needs to be done on perhaps finding better algorithms for mathFunction1 and mathFunction2. Especially useful would be to find unproven conjectures about mathProblem1 and/or mathProblem2 that would permit a better big-O growth for one or both of them, then draw attention to these as possible future work that improves your problem algorithm's asymptotic growth.

Also, sometimes big-O (i.e., big omicron) is neither easily theoretically determinable nor easily empirically measurable in practice given worst-case inputs; in this situation small omicron, theta, big omega, and/or small omega might be calculable or empirically measurable for revealing growth-sets of inputs, which also provides a rule-of-thumb idea of mathFunction1's and mathFunction2's growth characteristics which can be utilized to calculate the corresponding small omicron, theta, big omega, or small omega for your problem's algorithm.

Without doing any of this answer in original problem's situation, stating a big-O notation for the original problem's asymptotic growth other than O(n max(O(mathProblem1),O(mathProblem2))) is little better than saying “then a miracle occurs”. It is your job to dig deeper as very very very much as you can into characterizing mathFunction1 and mathFunction2 for your research to be any more than trivially useful (if not: entirely unhelpful, depending on the situation).

• Thank you for the well-written response. However, invalidating the question typically is not considered a "good" response on SO, which is what it seems you are doing. Feb 6, 2022 at 17:58
• @softwareevolved, the question is valid. My answer is valid. No invalidation occurred. My answer is (in my opinion) the very most correct one that I actually utilize in practice. Any other answer is hand-waving and not performing the required work. Also, this is not StackOverflow; this is a different StackExchange community. Feb 7, 2022 at 16:46
• @softwareevolved, you might not have wanted to hear the truth, but my answer is what is expected professionally, lest your work be maligned with the “then a miracle occurs” smear of being incomplete and dodging the difficult work. Your pursuit of effort reduction is not what is expected of professionals who do the heavy-lifting work. Feb 14, 2022 at 3:57