Time and space complexity of an algorithm and Purpose
Hi Experts,
I have confussion of the following algorithm in terms of time and space complexity and purpse. Could you find the above mentioned terms of the following algorithm.
Mystic Algorithm
๐๐๐๐๐๐๐ข๐๐๐๐ฆ๐ ๐ก๐๐๐ฆ๐ด๐๐(๐ฅ,๐)
๐๐ ๐=0 ๐กโ๐๐
๐๐๐ก๐ข๐๐ 1
๐๐๐ ๐๐
๐๐ ๐=1 ๐กโ๐๐
๐๐๐ก๐ข๐๐ ๐ฅ
๐๐๐ ๐๐
๐๐ ๐ ๐๐ ๐๐ฃ๐๐ ๐กโ๐๐
๐๐๐ก๐ข๐๐๐๐ฆ๐ ๐ก๐๐๐ฆ๐ด๐๐(๐ฅโ๐ฅ,๐2)
๐๐๐ ๐
๐๐๐ก๐ข๐๐ ๐๐ฆ๐ ๐ก๐๐๐ฆ๐ด๐๐(๐ฅโ๐ฅ,๐2)โ๐ฅ
๐๐๐ ๐๐ ๐๐๐ ๐๐๐๐๐๐๐ข๐๐
Comments
Is this an actual problem? The big O for a recursion function is O(bd) where b is the number of branches and d is the depth and the recursion. For this problem it appears that the recursion will not reach the base case unless the value of n selected is 0 or 1.
I guess the n2 means n/2. I found the same code here: https://stackoverflow.com/questions/50317996/figuring-out-the-time-complexity It's n/2 at this question. With this, it won't run indefinitely and n will be either 0 or 1 at some point