[Solved] Big O Notation/Time Complexity issue


It would be O(N).

The general approach to doing complexity analysis is to look for all significant constant-time executable statements or expressions (like comparisons, arithmetic operations, method calls, assignments) and work out an algebraic formula giving the number of times that they occur. Then reduce that formula to the equivalent big O complexity class.

In your case, method calls are significant.

When you have some experience at doing this, you will be able to leave out statements that “obviously” don’t contribute to the overall complexity. But to start with, it is a good exercise to count everything.

solved Big O Notation/Time Complexity issue