Search code examples
code-complexity

what is the code-complexity of n-x series?


If you had an algorithm with a loop that executed n steps the first time through, then n − 2 the second time, n − 4 the next time, and kept repeating until the last time through the loop it executed 2 steps, what would be the complexity measure of this loop? Is O(n-x) the correct format for the answer?


Solution

  • Its O(n^2) - that is the correct answer

    n steps each loop = n Number of times executing each loop is n/2

    Therefore n * n / 2 = Order n^2