Time complexity of a recursive function

点点圈 提交于 2020-01-07 09:29:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!