Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 Programmingimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

State the uses of job description.

Answered: 1 week ago

Question

Explain in detail the different methods of performance appraisal .

Answered: 1 week ago

Question

=+what kinds of policies and practices should be developed?

Answered: 1 week ago

Question

=+ Of the HR issues mentioned in the case,

Answered: 1 week ago