python - What is the complexity of this recursive algorithm? -


does following algorithm have complexity of o(nlogn)?

the thing confuses me algorithm divides twice, not once regular o(nlogn) algorithm, , each time o(n) work.

def equivalent(a, b):      if isequal(a, b):         return true      half = int(len(a) / 2)     if 2*half != len(a):         return false      if (equivalent(a[:half], b[:half]) , equivalent(a[half:], b[half:])):         return true      if (equivalent(a[:half], b[half:]) , equivalent(a[half:], b[:half])):         return true      return false 

each of 4 recursive calls equivalent reduces amount of input data factor of 2. thus, assuming a , b have same length, , isequal has linear time complexity, can construct recurrence relation overall complexity:

enter image description here

where c constant. can solve relation repeatedly substituting , spotting pattern:

enter image description here

what upper limit of summation, m? stopping condition occurs when len(a) odd. may anywhere between n , 1, depending on prime decomposition of n. in worse case scenario, n power of 2, function recurses until len(a) = 1, i.e.

enter image description here


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -