Question: Runtime Stack Consider the execution of this C/C++ program. bool isOdd ( int N ); // forward declaration of isOdd bool isEven ( int N
Runtime Stack
Consider the execution of this C/C++ program.
bool isOdd( int N ); // forward declaration of isOdd
bool isEven( int N ) {
if ( N == 0 ) return true;
else if ( N > 0 ) return isOdd( N 1 ); else return isOdd( N + 1 );
} bool isOdd( int N ) {
if ( N == 0 ) return false;
else if ( N > 0 ) return isEven( N 1 ); else return isEven( N + 1 );
} void main() {
int v = -3;
bool result = isEven( v );
}
1(a) [20 marks]
Run the above program (with v = -3) until the base case (N==0) is reached.
Draw the runtime stack at that time moment.
- Show clearly both the name and the value / pointer of each item. - Indicate each unknown value by ?.
1(b) [10 marks]
In the above program, the runtime stack grows large if the initial value of v is too large (e.g., 100) or too small (e.g., -100).
Propose a method for managing the runtime stack such that it occupies as little space as possible. Show some running steps of your method.
Functional Programming
Question1 Runtime Stack Consider the execution of this C/C++ program bool isoddint N bool isEven ( int N) /7 forward declaration of isOdd if(N== 0 ) else if (N>0return isOddN1; else return true; return isOdd(N+ 1 bool isodd int N ) return false; else if (N> 0 return isEven( N-1 else return isEven N+1 void main) int v 3; bool resultisEven ( v); I(a) [20 marks] Run the above program (with v--3) until the base case (N-0) is reached Draw the runtime stack at that time moment. Show clearly both the name and the value / pointer of each item Indicate each unknown value by?. 1(b) [10 marks] In the above program, the runtime stack grows large if the initial value of v is too large (e.g., 100) or too small (e.g., -100) Propose a method for managing the runtime stack such that it occupies as little space as possible. Show some running steps of your method
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
