I have written a simple algorithm to re-order the items in a list whenever the user drag and drop them. Also, if an item is deleted or a now one is added the list will be re-ordered. The algorithm contains three separated linear for loops (each one of them is O(n) ) and has two nested loops ( O(n^2) ). Is the total complexity O( n+ n +n + n^2) = O (3n+ n^2)?
How can I calculate the total big O ?
Thank you in advance
O(3n + n^2)is the same thing asO(n^2).Big O notation only describes limiting behavior, and both functions have the same limiting behavior — doubling
nquadruples them. (Asngoes to infinity, the3ncomponent becomes smaller and smaller relative to then^2component. At the limit, it completely dominates it.)