View Assessment Result: Multiple Choice Quiz 6



Your performance was as follows:

1.
How should a copy constructor function in a linked list class?

(a) It should copy all the nodes and the list header.
(b) It should copy the list header, but should copy the nodes only if there are less than four nodes.
(c) A linked list class should not have a copy constructor.
(d) It should copy only the list header, and not the nodes.

Correct answer is (a)

Your score on this question is: 10.00

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



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

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

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.
Which of the following is the main reason for using recursion?

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

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 following definition of a recursive function ff.

      int  ff( int n, int m )
      {
          if( n == 0 ) return m;
          return  ff( n - 1, m + 1 );
      }

If the values of n and m are nonnegative, what is returned by ff( n , m )?



(a) The greatest common divisor of n and m
(b) The product of n and m
(c) The sum 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



5.

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) log2 n
(b) 2 * n
(c) n2
(d) 2n

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



6.

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) unrestricted
(c) even
(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



7.

Consider the following definition of a recursive function what?

      int  what( int (*f)(int), int x, int n )
      {
            if( n == 0 )  return x;
            return  f( what( f, x, n - 1 ) );
      }

If n is a non-negative integer, then the call what( f, x, n )returns



(a) f(x) unless f is recursive, in which case it returns fn-1(x)
(b) fn(x)
(c) f(x)regardless of the value of n
(d) f(x + 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



8.

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 memory requirement is prohibitively large for large n.
(b) The depth of the recursion is prohibitively large for large n.
(c) The double recursion is difficult to implement.
(d) The total number of recursive calls is prohibitively large for large n.

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.
Given an array of length n, the extra space requirement in merge sort due the call stack is about

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

Correct answer is (a)

Your score on this question is: 10.00

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



10.

Assume List is a linked list of integers.

List  mystery( int a, int b, List L )
{
  if( L is empty ) return L;
  if(a == first(L)) return prepend( b, mystery(a, b, tail(L)) );
  return prepend( first(L), mystery( a, b, tail(L) ) );
}

The call mystery(a, b, L)returns a linked list just like L except that



(a) the list is reversed
(b) every occurrence of b has been replaced by an occurrence of a
(c) every occurrence of a has been replaced by an occurrence of b
(d) the list is rotated

Correct answer is (c)

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: 90.00