问题
I have a Java function that receives a matrix (2-dimensional array[][]) and creates a dynamic array of options of changes for this array, and then recursively creates a dynamic array for each option of the dynamic array. Eventually for each option in one of N options it creates N other options. I was told that the function of time complexity of it is T(n)=T(n)*n, is this possible? And what is the asymptotic time complexity of it in big O notation?
回答1:
If the recurrence relation is T(n)=nT(n) then the recursion never halts. That recurrence relation implies that every subproblem is the same size as the original problem. In a recursive function, if every subproblem is the same size as the original problem, that means that the recursion doesn't end. From your question it sounds like your function works once on the original matrix and then once on the results of the first function application, and then stops. That's not really a recursive function, and doesn't really fit the recurrence relation model for computing time complexity. It's also very simple to compute the time complexity of, though, because you can really just add up all of the computations.
来源:https://stackoverflow.com/questions/15853504/time-complexity-of-a-recursive-function