Lets say I have n
methods and I get a number i
, now I want to call method f_i
.
The trivial way to do this is to use conditionals like so:
if (j == 1) f_1();
else if (j == 2) f_2();
...
else if (j == n) f_n();
Since there are n comparisons in the worst case, the worst-case runtime is O(n).
Extra: How would you solve this if function f_i takes arguments p[i][1] to p[i][#parameters of f_i] where p is 2 dimensional array?