Home > other >  Help bosses!!!!!!
Help bosses!!!!!!

Time:09-27

Is the main reason, thank you!

CodePudding user response:

This article http://52luguan.xyz can solve your problem

CodePudding user response:

First, single cycle n times, O (n),
Second question, the outer loop n times, the inside of the loop to the outer variable values, similar to the triangular matrix traversal, needs n * n/2 operation, time complexity O (n),
Question 3, recursive calls n, O (n),

CodePudding user response:

There are more maliciously:
Fact (n) {
If (n=1) or (n=0) return 1
Else if (n % 2=0) return fact fact (n - 1) + (n - 2)
The else return (fact fact (n - 1) + (n - 2)) * 2
}
The time complexity (don't do the cache), take the T (n)=T (n - 1) + T (n - 2), the equivalent of a Fibonacci series, according to its general term formula, its time complexity is O (((1 + SQRT (5))/2) ^ n]
  • Related