Question: Analysis the following code: int RunningSum ( int n ) { if ( n = = 1 ) return 1 ; else return ( n
Analysis the following code:
int RunningSumint n
if n
return ;
else
return n RunningSumn;
During execution of the function call RunningSum RunningSum makes a function call to itself, with an argument of ie RunningSum However, before RunningSum ends, it makes a call to RunningSum And before RunningSum ends, it makes a call to RunningSum RunningSum however, makes no additional recursive calls and returns the value to RunningSum which enables RunningSum to end and return the value back to RunningSum This enables RunningSum to end and pass a value of to RunningSum The image pictorially shows how the execution of RunningSum proceeds.
Now, answer the following:
How many calls to RunningSum are made for the call RunningSum Explain your answer.
How about for the call RunningSumn Give your answer in terms of n Explain your answer.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
