Question: Consider the C function below! double fact (long i) { if (i==1 || i=0) return i; else return i*fact (i-1); } a) Assuming that
Consider the C function below! double fact (long i) { if (i==1 || i=0) return i; else return i*fact (i-1); } a) Assuming that n characterizes the input size, in terms of n, what is the number S of recursive calls? Also give the asymptotic upper bound (0)). b) How would you modify (i.e., rewrite) the function fact so as to eliminate the redundant recursive calls and reduce the number S of recursive calls? c) Solve (a) after the modification of the function fact. d) In terms of n, what is the value of sum in the function funcQ2 below? What is its asymptotic upper bound (O())? In funcQ2 use the first version of fact (i.e., given in (a)). double fact (long i) { if (i=-1 || i==0) return i; else return i*fact (i-1); } funcQ2 () ( } for (i-1; i
Step by Step Solution
There are 3 Steps involved in it
a In the original function fact the number of recursive calls S is equal to the value of i This is b... View full answer
Get step-by-step solutions from verified subject matter experts
