recursive functions
1 | int recursiveFun1(int n) |
The first function is being called recursively n times before reaching base case so its O(n), often called linear.
1 | int recursiveFun2(int n) |
The second function is called n-5 for each time, so we deduct five from n before calling the function, but n-5 is also O(n). (Actually called order of n/5 times. And, O(n/5) = O(n) ).
1 | int recursiveFun3(int n) |
This function is log(n) base 5, for every time we divide by 5 before calling the function so its O(log(n))(base 5), often called logarithmic and most often Big O notation and complexity analysis uses base 2.
1 | void recursiveFun4(int n, int m, int o) |
In the fourth, it’s O(2^n), or exponential, since each function call calls itself twice unless it has been recursed n times.
1 | int recursiveFun5(int n) |
In the fifth, the for loop takes n/2 since we’re increasing by 2, and the recursion take n-5 and since the for loop is called recursively therefore the time complexity is in (n-5) (n/2) = (2n-10) n = 2n^2- 10n, due to Asymptotic behavior and worst case scenario considerations or the upper bound that big O is striving for, we are only interested in the largest term so O(n^2).