what will be the time complexity of a recursive function to compute the x^n
What about a recursive function
public static void power(int num, int pow,int ans) { if(pow==0) { System.out.println(ans); return; } power(num,pow-1,ans*num); } is this function fine?
For the algorithm power(x, n) complexity is O(n) because the depth of recursion correlates with n linearly.