3

I wonder how we can perform algorithm analysis when in an algorithm we have calls of functions whose definition we do not know, e.g. functions delivered by external libraries.

Raphael
  • 72,336
  • 29
  • 179
  • 389
marekszpak
  • 165
  • 1
  • 5

1 Answers1

7

There are two ways to do this. If you're lucky, the implementer of the external library will have given you a runtime analysis of their code. If you're not, you can use an oracle model of computation. In a sense, this is treating the library routines as if they run in constant time. Of course, that would be ridiculous but an oracle-based analysis is a little smarter than that because it allows you to quantify how many times the oracle is accessed. For example, your answer might end up being something like, "The running time is $O(n^2)$ plus the cost of $O(\log n)$ calls to makeSausage() on instances of at most linear size."

David Richerby
  • 81,689
  • 26
  • 141
  • 235
  • 1
    That is, something like $O(n^2 + \log(n) \cdot T_{\mathtt{makeSausage}}(n))$, assuming makeSausage has a non-decreasing, polynomial runtime function. (For super-polynomial runtimes, a constant factor in the parameter would not translate to a constant factor of the result.) – Raphael Feb 03 '15 at 15:18