Solving the complexity of recursive time

Method a: Method substitution (substitution method)

This method is divided into two steps:
1,I guess the answer, We only need to guess substantially form
such as T (n) = 4T (n / 2) + n
by observing the recursion formula, n is doubled when noted, the output of four-fold increase, so speculation that the time complexity is recursion O (n- 2 ), i.e., T (n-) = O (n- 2 ).
2,Mathematical induction to prove
We constant coefficient of expansion tape
T (K) ≤ C . 1 K 2 -C 2 K (K <n-)
T (n-) ≤4 [C . 1 (n-/ 2) 2 -C 2 (n-/ 2)] + C = n- . 1 n- 2 + (1-2c 2 ) n-C = . 1 n- 2 -C 2 N- (C 2 -1) n≤c . 1 n-2-C ^ 2 n-
here we get a time complexity of O (n- 2 )

So why not CK 2 it, fancy style can not see, you can deduce what, simplified to CN 2 + the n-, this formula we get T (the n-) ≤cn 2 , it is achieved by reduced order ( calculate the time complexity we consider only the higher-order, do not control the low-order)

Method two: a recursive tree method (iterative method)

This formula should better understand it, is to unfold one by one, several geometric sequence mode to growth (d k-1 , each recursively d times, k is recursive layers), then here you can understood as a full d-tree .
Here Insert Picture Description

Published 41 original articles · won praise 20 · views 3097

Guess you like

Origin blog.csdn.net/weixin_44417475/article/details/104703670