How to tell which one is better
How to tell which one is better
In fact, both are O(n), which is consistent in terms of time complexity.
If I have to say which one is the best, it must be A2, because the time complexity increases with the increase of scale n, and the increment is the smallest.
The quality of the algorithm is mainly reflected when the scale is large. You will find how bad the algorithm is. When the scale is small, the current computer power can be completed instantly. Only when the scale is large can the algorithm be shown to be good. Bad, the scale is at least 10,000, that is, n=10,000. The algorithm complexity at this time is of practical significance. So you just look at the big n, whichever one is faster will be better