formula of the form master the complexity of T + (N) = a * T (N / b) O (N ^ d) of

Links: https://www.nowcoder.com/questionTerminal/fe9be0ec96a14b39b2ec5c90fd7d554b?orderByHotValue=1&page=1&onlyReference=false
Source: cattle off net
estimate the complexity of the recursive formula problem, as long as the complexity of the subject to the following formula, you can apply this formula time complexity

Examples: recursively find the maximum array T (N) = 2 * T (N / 2) + O (1)

 

T (N): sample size is N, the time complexity of
N: the parent sample issues
a: the number of sub-problems occur (parent problem is split into several sub-problems, no need to consider the recursive call, only consider parent-child relationship monolayer)
B: split into sub-problems, the amount of sample (amount of sample sub-problems need to be addressed) sub-problem, such as N are split into two halves, the sub-problem of sample N / 2
O (N ^ d): the remaining operating time complexity, beyond the call sub-process is removed, the remaining cost in the desired (normal operation was O (1))

    1. log (b, a)> d -> complexity is O (N ^ log (b, a))
    2. log (b, a) = d -> complexity is O (N ^ d * logN)
    3. log (b, a) <d -> complexity is O (N ^ d)
    4. log (b, a) to b expressed in base, a is the number of true

To find the K-big Partition algorithm as an example:

  Partition to find a single pivot axis is greater than (or small number), and in the best case, each array will be divided into two halves of the same length, running time T (N) = N + T (N / 2 )

  d=1,a=1,b=2.

  log (b, a) = log (2,1) = 0, less than d = 1, and therefore the complexity is O (n ^ d) = O (N)

Guess you like

Origin www.cnblogs.com/lxy-xf/p/11375447.html