Search code examples
javabig-oasymptotic-complexitykaratsuba

How would you n where one algorithm is preferred over another algorithm


I'm trying to compare two algorithms and their Big Oh efficiencies. I am trying to find the value for n where one algorithm becomes more efficient than the other algorithm. Any helpful examples or resources would be a huge help.


Solution

  • You really need to know more than just the BigO complexity of an algorithm in order to determine exactly at what point one algorithm becomes more efficient than another, assuming that they have different lower order terms and constants and that the one that has worse BigO characterics has better lower order terms\constants. But usually the approximation is enough.

    Runtime complexity of algorithms is the tool to use when dealing with problems of growing scale of input size.

    Empirical performance profiling is the tool to use when dealing with high frequency, repetitive problems that generally involve small inputs*

    (*) What constitutes small inputs depends on the complexity of the algorithms involved. For example, for the travelling salesman problem, an input of size 5 is small while an input of size 15 is huge. For sorting, 20 elements would be considered small, 20000 large and 2000000 would be huge.