What is the time complexity of the following method? Two options give me a lot of confusion. Thanks in advance.
public int count(int m, int n) { if(m == 1 || n == 1) return 1; return count(m-1, n) + count(m, n-1); }
It is in O(2^(n+m)).
O(2^(n+m))
This can be proved using induction, where the step of induction:
T(n,m) = T(n-1,m) + T(n, m-1) =(*) 2^(n+m-1) + 2^(n+m-1) = 2*2^(n+m-1) = 2^(n+m)
Where (*) is the induction hypothesis.
Source: https://habr.com/ru/post/1648285/More articles:Android Navigation View - Element Elements - androidWhat is the difference between IDbSet and DbSet? - c #Xamarin.Forms Version - xamarin.formsHow to synchronize Redux and Relay? - reactjsNavigate with options in the latest NativeScript with Angular and TypeScript - angularAndroid application crashes with error 6.0 when searching for permissions using ActivityCompat.requestPermissions - androidThe most efficient way to SELECT WHERE ID EXISTS IN rows in a second table is performanceHow to efficiently register row change rate in a Pandas DataFrame? - pythonHow to make links among other accessibility oriented texts - androidLayout transition between multiple passes in Vulcan - graphicsAll Articles