View Assessment Result: Multiple Choice Quiz 6



Your performance was as follows:

1.
What would be the consequences for algorithms if recursion were removed from C++?

(a) None
(b) Some algorithms could no longer be implemented.
(c) All algorithms could still be implemented, but the efficiency would often be catastrophically worse.
(d) All algorithms could still be implemented, but often less elegantly.

Correct answer is (d)

Your score on this question is: 0.00

Feedback:
   See section 1.6.1 of the course notes.
   (a) No Feedback



2.
Which of the following is the main reason for using recursion?

(a) To improve efficiency
(b) To obtain short, elegant solutions
(c) To use less memory
(d) To avoid templates and inheritance

Correct answer is (b)

Your score on this question is: 10.00

Feedback:
   See section 1.6.1 of the course notes.
   (b) No Feedback



3.
The specification for an algorithm must include all of the following EXCEPT:

(a) A precise description of the input
(b) A precise description of how the output is computed from the input
(c) A precise description of the output
(d) A precise description of all the data structures used

Correct answer is (d)

Your score on this question is: 10.00

Feedback:
   See section 1.6.1 of the course notes.
   (d) No Feedback



4.

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



(a) 3
(b) 2
(c) 5
(d) 1

Correct answer is (b)

Your score on this question is: 10.00

Feedback:
   See section 1.6.1 of the course notes.
   (b) No Feedback



5.

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 )?



(a) The sum of n and m
(b) The greatest common divisor of n and m
(c) The product of n and m
(d) The least common multiple of n and m

Correct answer is (c)

Your score on this question is: 10.00

Feedback:
   See section 1.6.1 of the course notes.
   (c) No Feedback



6.

Consider the following definition of a recursive function ff.

      int  ff( int n )
      {
          if( n == 0 ) return 1;
          return  2 * ff( n - 1 );
      }

If n > 0, what is returned by ff( n )?



(a) n2
(b) 2n
(c) 2 * n
(d) log2 n

Correct answer is (b)

Your score on this question is: 10.00

Feedback:
   See section 1.6.1 of the course notes.
   (b) No Feedback



7.

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



(a) odd
(b) even
(c) unrestricted
(d) non-negative

Correct answer is (d)

Your score on this question is: 10.00

Feedback:
   See section 1.6.1 of the course notes.
   (d) No Feedback



8.

Consider the following definition of a recursive function f.

      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



(a) a prime
(b) odd
(c) even
(d) a power of 2

Correct answer is (d)

Your score on this question is: 10.00

Feedback:
   See section 1.6.1 of the course notes.
   (d) No Feedback



9.

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?



(a) The depth of the recursion is prohibitively large for large n.
(b) The total number of recursive calls is prohibitively large for large n.
(c) The memory requirement is prohibitively large for large n.
(d) The double recursion is difficult to implement.

Correct answer is (b)

Your score on this question is: 0.00

Feedback:
   See section 1.6.1 of the course notes.
   (c) No Feedback



10.
Given an array of length n, the extra space requirement in merge sort due the call stack is about

(a) log n
(b) n2
(c) some small constant
(d) n

Correct answer is (d)

Your score on this question is: 0.00

Feedback:
   See section 1.6.1 of the course notes.
   (a) No Feedback



Go to top of assessment.

Total score: 70.00