Consider the function defined as follows.
int f( int n ) { if( n == 0 ) return 0; if( (n & 1) == 0 ) return f(n/2); return f(n/2) + 1; }
The value returned by the call f( 10 ); is
Consider the following definition of a recursive function ff.
int ff( int n, int m ) { if( n == 0 ) return 0; return ff( n - 1, m ) + m; }
If the values of n and m are nonnegative, what is returned by ff( n , m )?
int ff( int n ) { if( n == 0 ) return 1; return 2 * ff( n - 1 ); }
If n > 0, what is returned by ff( n )?
Consider the following definition of a recursive function f.
int f( int x ) { if( x == 0 ) return 1; return x * f( x - 1 ); }
The inputs for which f will terminate are all x such that x is
bool f( int x ) { if( (x & 1) == 1 ) return (x == 1); return f( x >> 1 ); // right shift }
The value returned by the call f(x)will determine whether the input x is
Consider the following recursive definition of a function to compute Fibonacci numbers.
int Fibonacci( int n ) { if( n == 0 ) return 0; if( n == 1 ) return 1; return F(n-1) + F(n-2); }
Why is the function Fibonacci problematic to use?