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 only the list header, and not the nodes.
(b) It should copy the list header, but should copy the nodes only if there are less than four nodes.
(c) It should copy all the nodes and the list header.
(d) A linked list class should not have a copy constructor.

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



2.
A recursive function is one that

(a) calls itself
(b) uses no loops of any kind
(c) calls other functions
(d) is called from main()

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



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

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

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



4.

Consider the following definition of a recursive function f.

      int  f( int n )
      {
          if( n == 0 ) return 0;
          if( (n & 1) == 0 ) return f(n/2);
          return f(n/2) + 1;
      }

What does f compute?



(a) A pseudo-random number between 1 and n
(b) The logarithm of the input
(c) The number of digits in the binary expansion of the input
(d) The number of 1's in the binary expansion of the input

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



5.

Assuming non-negative arguments, what is the purpose of the following recursive function?

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


(a) It computes (m + n)!
(b) It computes m * (n!)
(c) It computes the least common multiple of n and m.
(d) It computes the greatest common divisor of n and m.

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



6.

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 least common multiple of n and m
(c) The product of n and m
(d) The sum of n and m

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 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 least common multiple of n and m
(c) The greatest common divisor of n and m
(d) The product of n and m

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.

      int  f( int x )
      {
            if( x == 0 )  return 1;
            return  x * f( x );
      }

For which inputs x will the call f(x)terminate?



(a) For all even inputs x only
(b) For x = 0 only
(c) For all odd inputs x only
(d) For all inputs x

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



9.

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

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



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

(a) some small constant
(b) n2
(c) log n
(d) 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



Go to top of assessment.

Total score: 90.00