0

So the basic doubt i had started with this piece of code

def fn2(a,n):
    .
    .
    for i in range(0,n):
        .
        .
        .

def fn1():
    .
    .
    for i in range(1,n+1):
        fn2(a,i)

Would this be considered as a loop within a loop or will this take more than the usual O(n2) or would it take greater time then that ?

paws
  • 101
  • 1
  • If $fn1$ and $fn2$ do nothing depending on $n$ besides the for-loops, then it is $O(n^2)$. – fade2black Jul 03 '17 at 16:55
  • 1
    Imagine that you substitute the code of fn2 inside the code of fn1. Does this make the situation any clearer? – Yuval Filmus Jul 03 '17 at 17:33
  • no for clarity i just wrote about one loop in the example , actually fn2 is a function having multiple loops and memory allocations used as a subroutine within fn1 . – paws Jul 04 '17 at 07:06
  • You don't "consider as a loop within a loop". You count the operations. How many operations are there? – gnasher729 Jul 04 '17 at 08:32

0 Answers0