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

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



2.
A recursive function is one that

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

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



3.
How many calls to itself is a recursive function allowed to make?

(a) Any number
(b) None
(c) At most two
(d) At most one

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.
The specification for an algorithm must include all of the following EXCEPT:

(a) A precise description of how the output is computed from the input
(b) A precise description of the output
(c) A precise description of the input
(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



5.

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) 1
(c) 2
(d) 5

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 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) The logarithm of the input
(b) The number of 1's in the binary expansion of the input
(c) The number of digits in the binary expansion of the input
(d) A pseudo-random number between 1 and 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 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



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 x = 0 only
(b) For all inputs x
(c) For all even inputs x only
(d) For all odd inputs x only

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



9.

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) even
(c) a power of 2
(d) odd

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



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 rotated
(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 reversed

Correct answer is (c)

Your score on this question is: 0.00

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



Go to top of assessment.

Total score: 90.00