View Assessment Result: Multiple Choice Quiz 1



Your performance was as follows:

1.
What is the type name used to represent extra precision real numbers in C++?

(a) real
(b) double
(c) float
(d) long float

Correct answer is (b)

Your score on this question is: 0.00

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



2.
Assuming that Thing is some user-defined type, which of the following functions uses the least useful parameter list?

(a) bool f( Thing& x ); save space and permit f() to easily mutate the object
(b) bool f( Thing x ); give f() its own copy of x to work with.
(c) bool f( const Thing& x ); save space and protect the integrity of the object
(d) bool f( const Thing x ); f() gets its own copy of x, but is unable to mutate it.

Correct answer is (d)

Your score on this question is: 0.00

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



3.
Which of the following derived types is significantly different with respect to the other three?

(a) structure
(b) function
(c) union
(d) array

Correct answer is (b)

Your score on this question is: 10.00

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



4.
In C++, evaluation of the expression left && right is accurately described by which of the following? (Assume that left && right is a syntactically correct expression.)

(a) The expression right will be evaluated before the expression left is evaluated.
(b) The expression right will always be evaluated.
(c) The expression right will be evaluated if and only if the expression left evaluates to false.
(d) The expression right will be evaluated if and only if the expression left evaluates to true.

Correct answer is (d)

Your score on this question is: 10.00

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



5.

Suppose inf is an available ifstream and c is an available character. Consider the following code fragment.

do
    c = inf.get();
while (!inf.eof() && isspace(c));

Which of the following accurately describes the effect of executing this fragment?



(a) The number of non-white-space characters is counted.
(b) Characters are read until a non-white-space character is read or until the end of the file is reached.
(c) Characters are read until a white space is read.
(d) Characters are read until the end of the file is reached.

Correct answer is (b)

Your score on this question is: 10.00

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



6.
Assume that Thing is a user-defined type. Which of the following print functions for Thing is the safest and most efficient?

(a) void print( Thing* x );
(b) void print( const Thing& x );
(c) void print( Thing& x );
(d) void print( Thing x );

Correct answer is (b)

Your score on this question is: 10.00

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



7.

Compilers follow the "maximal munch rule" (read as many characters as can possibly be assembled into a meaningful syntactic construct). Therefore, what happens with the following?

      int a = 5; int b = 10;
     cout << (a+++++b) << " ";
     cout << a << " " << b << endl;


(a) Prints 15 6 11
(b) Prints 15 7 10
(c) Does not compile.
(d) Prints 16 6 11

Correct answer is (c)

Your score on this question is: 0.00

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



8.
Which of the following statements uses the C++ pre-increment operator?

(a) x += y;
(b) x = ++y;
(c) x = y++;
(d) x = y+y;

Correct answer is (b)

Your score on this question is: 10.00

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



9.
Which of the following expressions evaluates to true in C++ if and only if the index variable i is in bounds for an array of size 10?

(a) 0 <= i && i < 10
(b) 0 <= i < 10
(c) 0 <= i && i <= 10
(d) 0 < 10

Correct answer is (a)

Your score on this question is: 10.00

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



10.
Which company was responsible for the development of C++?

(a) Microsoft
(b) AT&T
(c) IBM
(d) SUN

Correct answer is (b)

Your score on this question is: 0.00

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



Go to top of assessment.

Total score: 60.00



Your performance was as follows:

1.
Which of the following derived types is significantly different with respect to the other three?

(a) array
(b) function
(c) union
(d) structure

Correct answer is (b)

Your score on this question is: 10.00

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



2.
Which of the following statements can be used to exit from a loop?

(a) break;
(b) continue;
(c) return;
(d) exit(0);

Correct answer is (a)

Your score on this question is: 10.00

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



3.

Under the declaration,

      int  n = 10;

which of the following loop constructs executes statement n times?



(a) do statement while( n-- );
(b) while( --n ) statement;
(c) for( int i = 1; i < n; i++ ) statement;
(d) while( n-- ) statement;

Correct answer is (d)

Your score on this question is: 10.00

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



4.

Consider the following code fragment.

      bool  b = false;
      int   f( int x ) { ... }
      cout << f(b) << endl;

Which of the following is true?



(a) This will compile and execute properly in part because in the function call the bool will be converted to an int.
(b) This will not compile.
(c) This will compile and execute properly in part because in the function call both bool and int are built-in types.
(d) This will compile and execute properly in part because in the function call the types match exactly.

Correct answer is (a)

Your score on this question is: 10.00

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



5.
Which of the following control structures can lead to non-terminating behavior?

(a) A while loop
(b) A switch statement
(c) An if-else statement
(d) A return statement

Correct answer is (a)

Your score on this question is: 10.00

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



6.
Assume that Thing is a user-defined type. Which of the following print functions for Thing is the safest and most efficient?

(a) void print( Thing* x );
(b) void print( Thing& x );
(c) void print( Thing x );
(d) void print( const Thing& x );

Correct answer is (d)

Your score on this question is: 10.00

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



7.

The "maximal munch rule" for compilers is to read as many characters as can possibly be assembled into a meaningful syntactic construct. Consider the following code fragment.

      int a = 5; int b = 10;
        cout << (a+++b) << " ";
      cout << a << " " << b << endl;

If the C++ compiler follows the maximal munch rule, what is printed as a result of the code fragment?



(a) 16 6 10
(b) 15 6 10
(c) 16 5 11
(d) 15 5 11

Correct answer is (b)

Your score on this question is: 10.00

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



8.
Which of the following lists of C++ types are ordered increasingly by size, as computed by sizeof() ?

(a) short, char, int, long
(b) char, short, int, long
(c) long, int, char, short
(d) long, int, short, char

Correct answer is (b)

Your score on this question is: 10.00

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



9.
Which of the following expressions evaluates to true in C++ if and only if the index variable i is in bounds for an array of size 10?

(a) 0 <= i < 10
(b) 0 < 10
(c) 0 <= i && i < 10
(d) 0 <= i && i <= 10

Correct answer is (c)

Your score on this question is: 10.00

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



10.
Which company was responsible for the development of C++?

(a) Microsoft
(b) AT&T
(c) SUN
(d) IBM

Correct answer is (b)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.

One reason for using an assert statement such as

      assert( 0 <= i && i < 10 );

within code is to



(a) instruct the compiler to set i to any value in the indicated range
(b) provide a comment for the user
(c) send a warning message but continue execution when the condition is violated
(d) terminate execution and send an error message whenever the condition is violated

Correct answer is (d)

Your score on this question is: 10.00

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



2.
Each of the following is a basic C++ type EXCEPT

(a) byte
(b) char
(c) bool
(d) unsigned int

Correct answer is (a)

Your score on this question is: 10.00

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



3.
The value of the C++ expression 10/3 is

(a) 4
(b) 1
(c) 3
(d) 3.33333

Correct answer is (c)

Your score on this question is: 10.00

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



4.
All of the following types can be used in a switch expression EXCEPT

(a) float
(b) int
(c) short
(d) enum

Correct answer is (a)

Your score on this question is: 10.00

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



5.

Consider the following code fragment.

      bool  b = false;
      int   f( int x ) { ... }
      cout << f(b) << endl;

Which of the following is true?



(a) This will compile and execute properly in part because in the function call both bool and int are built-in types.
(b) This will compile and execute properly in part because in the function call the types match exactly.
(c) This will not compile.
(d) This will compile and execute properly in part because in the function call the bool will be converted to an int.

Correct answer is (d)

Your score on this question is: 10.00

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



6.
How does C++ handle memory allocation?

(a) Allocation and deallocation is the responsibility of the programmer.
(b) Allocation and deallocation is completely shielded from the programmer.
(c) C++ always uses a garbage collector.
(d) C++ has a garbage collector that can be used or turned off.

Correct answer is (a)

Your score on this question is: 10.00

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



7.

The "maximal munch rule" for compilers is to read as many characters as can possibly be assembled into a meaningful syntactic construct. Consider the following code fragment.

      int a = 5; int b = 10;
        cout << (a+++b) << " ";
      cout << a << " " << b << endl;

If the C++ compiler follows the maximal munch rule, what is printed as a result of the code fragment?



(a) 15 5 11
(b) 15 6 10
(c) 16 5 11
(d) 16 6 10

Correct answer is (b)

Your score on this question is: 10.00

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



8.
Each of the following programming styles is well supported by C++ EXCEPT

(a) object-based programming (as in Java)
(b) object-oriented programming (as in Java)
(c) functional programming (as in Lisp)
(d) procedural programming (as in Pascal)

Correct answer is (c)

Your score on this question is: 0.00

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



9.
Which of the following lists of C++ types are ordered increasingly by size, as computed by sizeof() ?

(a) long, int, short, char
(b) long, int, char, short
(c) short, char, int, long
(d) char, short, int, long

Correct answer is (d)

Your score on this question is: 10.00

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



10.

Which of the following descriptions of C++ are true?

  1. It is a small, tidy language like C.
  2. It is a teaching language like Pascal.
  3. It is a safe, garbage collected language like Java.


(a) I only
(b) III only
(c) None
(d) I and II

Correct answer is (c)

Your score on this question is: 0.00

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



Go to top of assessment.

Total score: 80.00



Your performance was as follows:

1.
What is the type name used to represent single characters in C++?

(a) character
(b) Character
(c) Char
(d) char

Correct answer is (d)

Your score on this question is: 10.00

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



2.

One reason for using an assert statement such as

      assert( 0 <= i && i < 10 );

within code is to



(a) provide a comment for the user
(b) send a warning message but continue execution when the condition is violated
(c) terminate execution and send an error message whenever the condition is violated
(d) instruct the compiler to set i to any value in the indicated range

Correct answer is (c)

Your score on this question is: 10.00

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



3.
Each of the following is a basic C++ type EXCEPT

(a) byte
(b) unsigned int
(c) bool
(d) char

Correct answer is (a)

Your score on this question is: 10.00

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



4.
In C++, evaluation of the expression left && right is accurately described by which of the following? (Assume that left && right is a syntactically correct expression.)

(a) The expression right will always be evaluated.
(b) The expression right will be evaluated if and only if the expression left evaluates to true.
(c) The expression right will be evaluated before the expression left is evaluated.
(d) The expression right will be evaluated if and only if the expression left evaluates to false.

Correct answer is (b)

Your score on this question is: 10.00

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



5.
How does C++ handle memory allocation?

(a) Allocation and deallocation is the responsibility of the programmer.
(b) Allocation and deallocation is completely shielded from the programmer.
(c) C++ always uses a garbage collector.
(d) C++ has a garbage collector that can be used or turned off.

Correct answer is (a)

Your score on this question is: 10.00

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



6.
Assume that Thing is a user-defined type. Which of the following print functions for Thing is the safest and most efficient?

(a) void print( Thing x );
(b) void print( Thing& x );
(c) void print( const Thing& x );
(d) void print( Thing* x );

Correct answer is (c)

Your score on this question is: 10.00

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



7.
The signature of a function is

(a) the name of the function and its parameter list
(b) the body of the function
(c) the name of the function
(d) the number of parameters

Correct answer is (a)

Your score on this question is: 10.00

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



8.

Execution of the conditional statement

      if( x = expr ) ;

has what effect?



(a) The value of expr is assigned to x if and only if that value is true.
(b) The values of x and expr are evaluated and compared.
(c) A compile-time error is produced.
(d) The value of expr is assigned to x and then x is evaluated.

Correct answer is (d)

Your score on this question is: 10.00

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



9.
Which of the following expressions evaluates to true in C++ if and only if the index variable i is in bounds for an array of size 10?

(a) 0 <= i && i < 10
(b) 0 < 10
(c) 0 <= i && i <= 10
(d) 0 <= i < 10

Correct answer is (a)

Your score on this question is: 10.00

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



10.
Which company was responsible for the development of C++?

(a) AT&T
(b) IBM
(c) SUN
(d) Microsoft

Correct answer is (a)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.
Assuming that Thing is some user-defined type, which of the following functions uses the least useful parameter list?

(a) bool f( Thing& x ); save space and permit f() to easily mutate the object
(b) bool f( const Thing x ); f() gets its own copy of x, but is unable to mutate it.
(c) bool f( const Thing& x ); save space and protect the integrity of the object
(d) bool f( Thing x ); give f() its own copy of x to work with.

Correct answer is (b)

Your score on this question is: 10.00

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



2.
Which of the following derived types is significantly different with respect to the other three?

(a) array
(b) union
(c) structure
(d) function

Correct answer is (d)

Your score on this question is: 10.00

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



3.

Suppose inf is an available ifstream and c is an available character. Consider the following code fragment.

do
    c = inf.get();
while (!inf.eof() && isspace(c));

Which of the following accurately describes the effect of executing this fragment?



(a) Characters are read until the end of the file is reached.
(b) Characters are read until a non-white-space character is read or until the end of the file is reached.
(c) Characters are read until a white space is read.
(d) The number of non-white-space characters is counted.

Correct answer is (b)

Your score on this question is: 10.00

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



4.

Consider the following code fragment.

      bool  b = false;
      int   f( int x ) { ... }
      cout << f(b) << endl;

Which of the following is true?



(a) This will compile and execute properly in part because in the function call the types match exactly.
(b) This will compile and execute properly in part because in the function call the bool will be converted to an int.
(c) This will compile and execute properly in part because in the function call both bool and int are built-in types.
(d) This will not compile.

Correct answer is (b)

Your score on this question is: 10.00

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



5.
Which of the following control structures can lead to non-terminating behavior?

(a) A while loop
(b) An if-else statement
(c) A switch statement
(d) A return statement

Correct answer is (a)

Your score on this question is: 10.00

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



6.
Which of the following is true about the default parameter passing mechanism in C++ ?

(a) It is call-by-reference.
(b) It is chosen automatically by the compiler.
(c) It is call-by-value.
(d) It depends on where the function is defined.

Correct answer is (c)

Your score on this question is: 10.00

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



7.

The "maximal munch rule" for compilers is to read as many characters as can possibly be assembled into a meaningful syntactic construct. Consider the following code fragment.

      int a = 5; int b = 10;
        cout << (a+++b) << " ";
      cout << a << " " << b << endl;

If the C++ compiler follows the maximal munch rule, what is printed as a result of the code fragment?



(a) 15 6 10
(b) 16 6 10
(c) 15 5 11
(d) 16 5 11

Correct answer is (a)

Your score on this question is: 10.00

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



8.
Which of the following statements uses the C++ pre-increment operator?

(a) x += y;
(b) x = ++y;
(c) x = y++;
(d) x = y+y;

Correct answer is (b)

Your score on this question is: 10.00

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



9.
The signature of a function is

(a) the name of the function and its parameter list
(b) the name of the function
(c) the body of the function
(d) the number of parameters

Correct answer is (a)

Your score on this question is: 10.00

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



10.

Which of the following descriptions of C++ are true?

  1. It is a small, tidy language like C.
  2. It is a teaching language like Pascal.
  3. It is a safe, garbage collected language like Java.


(a) None
(b) I only
(c) I and II
(d) III only

Correct answer is (a)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.
Consider the following code fragment. Thing *tp = new Thing; tp = new Thing; Which of the following is true concerning this code fragment?

(a) When executed, it creates two instances of Thing and makes the first point to the second.
(b) When executed, it creates a new instance of Thing and then loses all access to it as it creates yet another instance.
(c) When executed, it creates a new instance of Thing and then overwrites it by yet another instance.
(d) It will not compile.

Correct answer is (b)

Your score on this question is: 10.00

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



2.

What, if anything, is wrong with the following code fragment?

      bool  *bp;  int  x;
      bp = &x;


(a) The assignment should be *bp = &x;.
(b) A pointer to an int cannot be assigned to a variable that is a pointer to a bool.
(c) The & should be a *.
(d) Nothing

Correct answer is (b)

Your score on this question is: 0.00

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



3.
Which of the following types of memory is most likely to cause the production of errors in a program?

(a) The free store.
(b) Automatic memory.
(c) Static memory.
(d) They are all equally dangerous in C++.

Correct answer is (a)

Your score on this question is: 10.00

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



4.

The parameters in the main part of a program often take one of the two following forms.

    Version 1:  int  main( int argc, char **argv )
    Version 2:  int  main( int argc, char *argv[] )

What is the difference between the two?



(a) Version 1 uses a variable-size array, but Version 2 uses a fixed-size array.
(b) Version 1 uses a linked list of strings, but version 2 uses an array.
(c) Version 1 uses one long array of chars, but version 2 uses several small arrays
(d) None

Correct answer is (d)

Your score on this question is: 10.00

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



5.

Consider the following declarations.

      int  (*f)(int);
      int   *g(int);

Which of the following correctly characterizes f and g?

  1. f is a pointer to a function from integers to integers, and g is a function from integers to pointers to integers.
  2. both f and g are functions from integers to pointers to integers
  3. f is a function from integers to pointers to integers, and g is a pointer to a function from integers to integers


(a) II only
(b) III only
(c) I only
(d) none

Correct answer is (c)

Your score on this question is: 10.00

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



6.
The Golden Rule for memory management in C++ is that

(a) every call to new must have a matching call to delete
(b) allocation must always come before deallocation
(c) every programmer-defined call to new will be matched by the compiler by a call to delete
(d) memory should always be initialized after allocation

Correct answer is (a)

Your score on this question is: 10.00

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



7.
C++ currently supports two types of strings: null-terminated C-style strings, and the string class in the Standard Library. Which of the following claims is false?

(a) The string class provides more operations than the C string library.
(b) A C++ program may use either null-terminated strings or the string class, but not both.
(c) Null-terminated strings can be processed efficiently with pointers.
(d) For simple tasks dealing with many short strings, null-terminated strings are the implementation of choice.

Correct answer is (b)

Your score on this question is: 10.00

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



8.

Consider the following code fragment.

      int  A[100], *p, *q;
      for( p = A, q = p + 99; p < A+100; p++, q-- )
            swap( p, q );

Execution of this code fragment has what effect on the array A?



(a) It has no effect.
(b) It zeroes out the whole array.
(c) It rotates the array 1 place to the left.
(d) It reverses the array.

Correct answer is (a)

Your score on this question is: 10.00

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



9.

Consider the following code fragment.

      char  *str1 = "word";
      char  *str2;
      str2 = str1;

Which of the following correctly characterizes the effect of executing this fragment?



(a) The null-terminated string "word" is copied to str2.
(b) The pointer str2 is set so as to point at the first character in the null-terminated string "word".
(c) The non-null characters of "word" are copied to str2.
(d) Nothing is changed.

Correct answer is (b)

Your score on this question is: 10.00

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



10.

What, if anything, is wrong with the following code fragment?

      Thing  *ptr = new Thing;
      ptr = NULL;


(a) When executed, it will assign a NULL pointer to a variable that is a pointer to a Thing.
(b) When executed, it will create an instance of Thing and then remove the only reference to this instance without destroying it first.
(c) Nothing
(d) When executed, it will create an instance of Thing and then overwrite it with NULL.

Correct answer is (b)

Your score on this question is: 0.00

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



Go to top of assessment.

Total score: 80.00



Your performance was as follows:

1.
Suppose a user-defined class Thing has a simple constructor that does not require any calls to new. Which of the following is true about the destructor?

(a) In this case, no destructor is required for class Thing.
(b) The appropriate destructor will be provided automatically by the compiler.
(c) It will not contain calls to delete.
(d) It might contain calls to delete, but might not.

Correct answer is (d)

Your score on this question is: 0.00

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



2.

Assume that Thing is a user-defined class, and consider the following function.

Thing  f(Thing& A)  {
  Thing B;
  B.x  =  A.x;
  return B;
}

Where in this code will a copy constructor be used?



(a) In copying the data from A to B
(b) In the return operation
(c) In the creation of the local variable B
(d) In passing the parameter

Correct answer is (b)

Your score on this question is: 0.00

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



3.
If a user-defined class overloads both operator== and operator<, which other operator, if any, is implicitly overloaded as a consequence?

(a) operator!=
(b) operator<=
(c) operator<<
(d) No other operator

Correct answer is (d)

Your score on this question is: 0.00

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



4.
A user-defined class Thing that has value semantics behaves very much like

(a) any class that has a default constructor
(b) an expression of arithmetic
(c) a pointer to a built-in type such as int* or float*
(d) a built-in type such as int or float

Correct answer is (d)

Your score on this question is: 10.00

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



5.
What is the difference between a C++ class and a C++ struct ?

(a) Structs cannot contain function members.
(b) There is no difference.
(c) The default access in a class is private and in a struct is public.
(d) The default access in a class is public and in a struct is private.

Correct answer is (c)

Your score on this question is: 10.00

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



6.
The purpose of a constructor is to

(a) handle assignments between instances of the class
(b) clean up memory when an instance goes out of scope
(c) prevent memory leaks
(d) initialize data members of a class properly after space has been allocated

Correct answer is (d)

Your score on this question is: 10.00

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



7.
The purpose of a copy constructor is to

(a) initialize memory when an instance is first created
(b) facilitate assignments between instances of the class
(c) make otherwise identical copies of objects
(d) prevent memory leaks

Correct answer is (c)

Your score on this question is: 10.00

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



8.

Assume that Thing is a user-defined class, and consider the following code fragment, where B is an instance of Thing.

      Thing  A = B

Which of the following is a class member that is used in this code fragment?



(a) The assignment operator
(b) The default constructor
(c) The copy constructor
(d) The destructor

Correct answer is (c)

Your score on this question is: 10.00

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



9.

Consider the following class outline for a user-defined implementation of real numbers.

      class  RealNumber {
      ...
             RealNumber( float x );
             RealNumber( float x, float y=0 );
      };

What, if anything, is wrong with the outline?



(a) Default values are not allowed in constructors.
(b) Nothing
(c) The second constructor conflicts with the first.
(d) There is no reasonable way to construct a real from two real parameters.

Correct answer is (c)

Your score on this question is: 0.00

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



10.
Which of the following statements properly describes the restriction in C++ regarding what a function can return?

(a) Neither functions nor function objects can be returned.
(b) Functions cannot be returned, but function objects can be returned.
(c) Function pointers cannot be returned, but function objects can be returned.
(d) Neither function pointers nor function objects can be returned.

Correct answer is (b)

Your score on this question is: 0.00

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



Go to top of assessment.

Total score: 50.00



Your performance was as follows:

1.
To which of the following is object-based programming ideally suited?

(a) Encapsulation
(b) Implementing simple monolithic programs
(c) Providing elegant mechanisms for code reuse
(d) Attaining the highest possible efficiency

Correct answer is (a)

Your score on this question is: 0.00

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



2.
Suppose a user-defined class Thing has a simple constructor that does not require any calls to new. Which of the following is true about the destructor?

(a) The appropriate destructor will be provided automatically by the compiler.
(b) It will not contain calls to delete.
(c) In this case, no destructor is required for class Thing.
(d) It might contain calls to delete, but might not.

Correct answer is (d)

Your score on this question is: 10.00

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



3.
Of the following methods, which is least important in a user-defined class with value semantics?

(a) A copy constructor
(b) A destructor
(c) The assignment operator
(d) The output operator

Correct answer is (d)

Your score on this question is: 10.00

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



4.

Assume that Thing is a user-defined class, and consider the following function.

Thing  f(Thing& A)  {
  Thing B;
  B.x  =  A.x;
  return B;
}

Where in this code will a copy constructor be used?



(a) In the creation of the local variable B
(b) In copying the data from A to B
(c) In passing the parameter
(d) In the return operation

Correct answer is (d)

Your score on this question is: 10.00

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



5.
If a user-defined class overloads both operator== and operator<, which other operator, if any, is implicitly overloaded as a consequence?

(a) operator<<
(b) operator!=
(c) operator<=
(d) No other operator

Correct answer is (d)

Your score on this question is: 10.00

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



6.
The purpose of a constructor is to

(a) prevent memory leaks
(b) initialize data members of a class properly after space has been allocated
(c) handle assignments between instances of the class
(d) clean up memory when an instance goes out of scope

Correct answer is (b)

Your score on this question is: 10.00

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



7.
The purpose of the assignment operator is to

(a) initialize data members when an instance is first created
(b) be used internally in an object's copy constructor
(c) prevent memory leaks
(d) provide for proper assignment between objects

Correct answer is (d)

Your score on this question is: 10.00

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



8.

Consider the following class outline for a user-defined implementation of real numbers.

      class  RealNumber {
            ...
            private:
                    RealNumber(void) {}
      };

Which of the following is true about such an implementation?



(a) Since the class defines a private constructor, it cannot define any public constructors.
(b) It exhibits good general defensive programming by using private constructors.
(c) All RealNumber objects will be read-only.
(d) It will be impossible to place RealNumber objects into a container.

Correct answer is (d)

Your score on this question is: 10.00

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



9.

Consider the following class outline for a user-defined implementation of real numbers.

      class  RealNumber {
      ...
             RealNumber( float x );
             RealNumber( float x, float y=0 );
      };

What, if anything, is wrong with the outline?



(a) Nothing
(b) The second constructor conflicts with the first.
(c) Default values are not allowed in constructors.
(d) There is no reasonable way to construct a real from two real parameters.

Correct answer is (b)

Your score on this question is: 10.00

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



10.
Which of the following correctly describes the difference between an ordinary function and a function object?

(a) The compiler can perform type checking with function objects.
(b) Function objects execute faster on some machines.
(c) Functions are allowed to be recursive.
(d) A function object may contain data that persist between calls.

Correct answer is (d)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 90.00



Your performance was as follows:

1.
Suppose a user-defined class Thing has a simple constructor that does not require any calls to new. Which of the following is true about the destructor?

(a) It will not contain calls to delete.
(b) In this case, no destructor is required for class Thing.
(c) It might contain calls to delete, but might not.
(d) The appropriate destructor will be provided automatically by the compiler.

Correct answer is (c)

Your score on this question is: 10.00

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



2.
What is the most compelling reason for a random number generator to be implemented as a function object?

(a) A random number generator needs to maintain state between uses
(b) Efficiency
(c) The use of a function object can increase the "randomness" of the generator
(d) So that the generator can be seeded

Correct answer is (a)

Your score on this question is: 0.00

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



3.
Of the following methods, which is least important in a user-defined class with value semantics?

(a) The assignment operator
(b) The output operator
(c) A destructor
(d) A copy constructor

Correct answer is (b)

Your score on this question is: 10.00

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



4.

Assume that Thing is a user-defined class, and consider the following function.

Thing  f(Thing& A)  {
  Thing B;
  B.x  =  A.x;
  return B;
}

Where in this code will a copy constructor be used?



(a) In the creation of the local variable B
(b) In the return operation
(c) In copying the data from A to B
(d) In passing the parameter

Correct answer is (b)

Your score on this question is: 10.00

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



5.
In a C++ class, access to data members and function members are typically

(a) both public
(b) public and private, respectively
(c) both private
(d) private and public, respectively

Correct answer is (d)

Your score on this question is: 10.00

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



6.
The purpose of a copy constructor is to

(a) facilitate assignments between instances of the class
(b) initialize memory when an instance is first created
(c) prevent memory leaks
(d) make otherwise identical copies of objects

Correct answer is (d)

Your score on this question is: 10.00

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



7.

Consider the following class outline for a user-defined implementation of real numbers.

      class  RealNumber {
      ...
             RealNumber( float x );
             RealNumber( float x, float y=0 );
      };

What, if anything, is wrong with the outline?



(a) The second constructor conflicts with the first.
(b) Nothing
(c) There is no reasonable way to construct a real from two real parameters.
(d) Default values are not allowed in constructors.

Correct answer is (a)

Your score on this question is: 10.00

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



8.

Consider the class outline below.

      class  Stack {
      ...
             explicit Stack( int n );
      };

What is the purpose of the explicit in this outline?



(a) To make sure that the constructor does not apply to short, only to int
(b) To draw attention to the fact that there is a constructor
(c) To prevent the Stack destructor from damaging the data stored in the stack
(d) To inhibit automatic conversions from an integer to a Stack

Correct answer is (d)

Your score on this question is: 10.00

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



9.
Which of the following statements properly describes the restriction in C++ regarding what a function can return?

(a) Functions cannot be returned, but function objects can be returned.
(b) Function pointers cannot be returned, but function objects can be returned.
(c) Neither function pointers nor function objects can be returned.
(d) Neither functions nor function objects can be returned.

Correct answer is (a)

Your score on this question is: 10.00

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



10.
Which of the following correctly describes the difference between an ordinary function and a function object?

(a) A function object may contain data that persist between calls.
(b) Functions are allowed to be recursive.
(c) The compiler can perform type checking with function objects.
(d) Function objects execute faster on some machines.

Correct answer is (a)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 90.00



Your performance was as follows:

1.
Suppose a user-defined class Thing has a simple constructor that does not require any calls to new. Which of the following is true about the destructor?

(a) In this case, no destructor is required for class Thing.
(b) It will not contain calls to delete.
(c) The appropriate destructor will be provided automatically by the compiler.
(d) It might contain calls to delete, but might not.

Correct answer is (d)

Your score on this question is: 10.00

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



2.
What is the most compelling reason for a random number generator to be implemented as a function object?

(a) The use of a function object can increase the "randomness" of the generator
(b) Efficiency
(c) A random number generator needs to maintain state between uses
(d) So that the generator can be seeded

Correct answer is (c)

Your score on this question is: 10.00

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



3.
A user-defined class Thing that has value semantics behaves very much like

(a) a pointer to a built-in type such as int* or float*
(b) an expression of arithmetic
(c) a built-in type such as int or float
(d) any class that has a default constructor

Correct answer is (c)

Your score on this question is: 10.00

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



4.
What is the difference between a C++ class and a C++ struct ?

(a) The default access in a class is private and in a struct is public.
(b) There is no difference.
(c) Structs cannot contain function members.
(d) The default access in a class is public and in a struct is private.

Correct answer is (a)

Your score on this question is: 10.00

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



5.
In a C++ class, access to data members and function members are typically

(a) both private
(b) private and public, respectively
(c) public and private, respectively
(d) both public

Correct answer is (b)

Your score on this question is: 10.00

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



6.
The purpose of a constructor is to

(a) handle assignments between instances of the class
(b) clean up memory when an instance goes out of scope
(c) prevent memory leaks
(d) initialize data members of a class properly after space has been allocated

Correct answer is (d)

Your score on this question is: 10.00

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



7.
The purpose of the assignment operator is to

(a) prevent memory leaks
(b) be used internally in an object's copy constructor
(c) initialize data members when an instance is first created
(d) provide for proper assignment between objects

Correct answer is (d)

Your score on this question is: 10.00

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



8.

Assume that Thing is a user-defined class, and consider the following code fragment, where B is an instance of Thing.

      Thing  A = B

Which of the following is a class member that is used in this code fragment?



(a) The default constructor
(b) The assignment operator
(c) The copy constructor
(d) The destructor

Correct answer is (c)

Your score on this question is: 10.00

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



9.

Consider the class outline below.

      class  Stack {
      ...
             explicit Stack( int n );
      };

What is the purpose of the explicit in this outline?



(a) To make sure that the constructor does not apply to short, only to int
(b) To draw attention to the fact that there is a constructor
(c) To prevent the Stack destructor from damaging the data stored in the stack
(d) To inhibit automatic conversions from an integer to a Stack

Correct answer is (d)

Your score on this question is: 10.00

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



10.
Which of the following correctly describes the difference between an ordinary function and a function object?

(a) A function object may contain data that persist between calls.
(b) Function objects execute faster on some machines.
(c) The compiler can perform type checking with function objects.
(d) Functions are allowed to be recursive.

Correct answer is (a)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.
To which of the following is object-based programming ideally suited?

(a) Implementing simple monolithic programs
(b) Encapsulation
(c) Attaining the highest possible efficiency
(d) Providing elegant mechanisms for code reuse

Correct answer is (b)

Your score on this question is: 10.00

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



2.
Suppose a user-defined class Thing has a simple constructor that does not require any calls to new. Which of the following is true about the destructor?

(a) In this case, no destructor is required for class Thing.
(b) It might contain calls to delete, but might not.
(c) The appropriate destructor will be provided automatically by the compiler.
(d) It will not contain calls to delete.

Correct answer is (b)

Your score on this question is: 10.00

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



3.
Of the following methods, which is least important in a user-defined class with value semantics?

(a) A copy constructor
(b) The assignment operator
(c) The output operator
(d) A destructor

Correct answer is (c)

Your score on this question is: 10.00

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



4.
If a user-defined class Complex has overloaded operator+=, then one would expect this operator to have which of the following declarations?

(a) void operator+=( float real, float imag );
(b) Complex& operator+=( const Complex& rhs );
(c) Complex& operator+=( const Complex rhs );
(d) void operator+=( const Complex& rhs );

Correct answer is (b)

Your score on this question is: 10.00

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



5.
If a user-defined class overloads both operator== and operator<, which other operator, if any, is implicitly overloaded as a consequence?

(a) No other operator
(b) operator<<
(c) operator<=
(d) operator!=

Correct answer is (a)

Your score on this question is: 10.00

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



6.
What is the difference between a C++ class and a C++ struct ?

(a) The default access in a class is private and in a struct is public.
(b) The default access in a class is public and in a struct is private.
(c) Structs cannot contain function members.
(d) There is no difference.

Correct answer is (a)

Your score on this question is: 10.00

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



7.
In a C++ class, access to data members and function members are typically

(a) both public
(b) public and private, respectively
(c) private and public, respectively
(d) both private

Correct answer is (c)

Your score on this question is: 10.00

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



8.
The purpose of a constructor is to

(a) prevent memory leaks
(b) handle assignments between instances of the class
(c) initialize data members of a class properly after space has been allocated
(d) clean up memory when an instance goes out of scope

Correct answer is (c)

Your score on this question is: 10.00

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



9.

Consider the following class outline for a user-defined implementation of real numbers.

      class  RealNumber {
            ...
            private:
                    RealNumber(void) {}
      };

Which of the following is true about such an implementation?



(a) It will be impossible to place RealNumber objects into a container.
(b) Since the class defines a private constructor, it cannot define any public constructors.
(c) It exhibits good general defensive programming by using private constructors.
(d) All RealNumber objects will be read-only.

Correct answer is (a)

Your score on this question is: 10.00

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



10.
Which of the following statements properly describes the restriction in C++ regarding what a function can return?

(a) Neither functions nor function objects can be returned.
(b) Neither function pointers nor function objects can be returned.
(c) Function pointers cannot be returned, but function objects can be returned.
(d) Functions cannot be returned, but function objects can be returned.

Correct answer is (d)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.

In a template definition

      template<class T>  ...

the template parameter T ranges over



(a) only built-in types
(b) classes as well as structs
(c) all types
(d) only user-defined classes

Correct answer is (c)

Your score on this question is: 10.00

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



2.

Consider the following template specification.

      template<int n>  ...

In use, the template parameter n can be replaced by



(a) arithmetic type values only
(b) any type of value
(c) int values and int containers only
(d) int values only

Correct answer is (d)

Your score on this question is: 0.00

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



3.

Consider the following templated array copy function and arrays.

      template<class T>  void  copy( T a[], T b[], int n ) {
          for(int i = 0; i < n; i++ ) a[i] = b[i];
      }
      char   C[10], CC[10];
      int    I[10];
      float  F[10];

Which of the following calls to copy would produce a compile time error?



(a) copy( I, (int*)F, 10 );
(b) copy( C, CC, 10 );
(c) copy( I, F, 10 );
(d) copy( I, I, 10 );

Correct answer is (c)

Your score on this question is: 10.00

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



4.

Consider the following templated swap function and data types.

      template<class T>  void  swap( T& a, T& b ){
          T tmp = a; a = b; b = tmp;
      }
      char   c1, c2;
      int    i1, i2;
      float  A[10];

Which of the following calls to swap produces a compile time error?

  1. swap( i1, c2 )
  2. swap( c1, i2 );
  3. swap( A[5], A[2] );


(a) II and III
(b) I only
(c) I, II, and III
(d) I and II

Correct answer is (d)

Your score on this question is: 10.00

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



5.
Which of the following is true about the run-time efficiency of using templated functions versus using nontemplated functions?

(a) The run-time efficiency is the same for both.
(b) The run-time efficiency is much worse than for templated functions.
(c) The run-time efficiency is better for templated functions.
(d) The run-time efficiency is slightly worse for templated functions.

Correct answer is (a)

Your score on this question is: 0.00

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



6.
Which of the following is true about compilation of a templated function or class?

(a) Templates are not handled during compilation.
(b) Compilation takes much, much longer.
(c) Compilation takes less time.
(d) Compilation takes slightly longer.

Correct answer is (d)

Your score on this question is: 0.00

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



7.

What, if anything, is wrong with the following function declaration?

      template<class A, class B>  A  f( B x );


(a) The compiler cannot determine A when f is called.
(b) Nothing
(c) The compiler cannot determine B when f is called.
(d) The parameter should be passed by reference.

Correct answer is (a)

Your score on this question is: 0.00

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



8.

Consider the following outline of a templated sorting function.

      template<class T>  void  sort( T a[], int n ) { ... }

For a given sorting algorithm S, which of the following is true about using this outline to implement S?



(a) It is a reasonable way to implement S.
(b) It is a poor choice since it does not work with linked lists.
(c) It is a poor choice since templates slow down sorting.
(d) It is impossible since the algorithm cannot know how to compare two instances of type T.

Correct answer is (a)

Your score on this question is: 10.00

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



9.

Consider the following outline of a templated array class.

      template<class T>  class Array { ... }

Which of the declarations below is in obvious error with respect to using such a class?



(a) Array<int> A(10);
(b) Array<int> A;
(c) Array<int> A<int>;
(d) Array<int> A(10,0);

Correct answer is (c)

Your score on this question is: 10.00

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



10.

Consider the following templated function.

   template<class T> T Apply( T x, T (*ff)(T) ){ return ff(x); }

Which of the following is true concerning its use?



(a) The input function can be arbitrary, and the templated function returns a pointer to the result of calling the second input on the first input.
(b) The input function must return the same type as its argument, and the templated function returns the result of calling the second input on the first input.
(c) The input function can be arbitrary, and the templated function returns the result of calling the second input on the first input.
(d) The input function must return the same type as its argument, and the templated function returns a pointer to the result of calling the second input on the first input.

Correct answer is (b)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 60.00



Your performance was as follows:

1.

Consider the following template specification.

      template<int n>  ...

In use, the template parameter n can be replaced by



(a) int values only
(b) any type of value
(c) int values and int containers only
(d) arithmetic type values only

Correct answer is (a)

Your score on this question is: 10.00

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



2.

Consider the following templated array copy function and arrays.

      template<class T>  void  copy( T a[], T b[], int n ) {
          for(int i = 0; i < n; i++ ) a[i] = b[i];
      }
      char   C[10], CC[10];
      int    I[10];
      float  F[10];

Which of the following calls to copy would produce a compile time error?



(a) copy( I, F, 10 );
(b) copy( I, I, 10 );
(c) copy( C, CC, 10 );
(d) copy( I, (int*)F, 10 );

Correct answer is (a)

Your score on this question is: 10.00

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



3.

Consider the following templated array copy function and arrays.

      template<class S, class T>  void  copy( S a[], T b[], int n ) {
          for(int i = 0; i < n; i++ ) a[i] = b[i];
      }
      char   C[10];
      int    I[10];
      float  F[10];

Which of the following calls to copy would produce a compile time error?

  1. copy( F, C, 10 );
  2. copy( I, C, 10 );
  3. copy( C, F, 10 );


(a) I
(b) II
(c) III
(d) None

Correct answer is (d)

Your score on this question is: 10.00

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



4.

Consider the following templated swap function and data types.

      template<class T>  void  swap( T& a, T& b ){
          T tmp = a; a = b; b = tmp;
      }
      char   c1, c2;
      int    i1, i2;
      float  A[10];

Which of the following calls to swap produces a compile time error?

  1. swap( i1, c2 )
  2. swap( c1, i2 );
  3. swap( A[5], A[2] );


(a) I, II, and III
(b) I and II
(c) II and III
(d) I only

Correct answer is (b)

Your score on this question is: 10.00

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



5.

Consider the following templated swap function.

      template<class T>  void  swap( T& a, T& b ){
          T tmp = a; a = b; b = tmp;
      }

Determining the right choice of type parameter T occurs at which of the following times?



(a) Run time only
(b) In part at compile time, and in part at run time
(c) Link time
(d) Compile time only

Correct answer is (d)

Your score on this question is: 0.00

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



6.
Which of the following is true about the run-time efficiency of using templated functions versus using nontemplated functions?

(a) The run-time efficiency is slightly worse for templated functions.
(b) The run-time efficiency is much worse than for templated functions.
(c) The run-time efficiency is better for templated functions.
(d) The run-time efficiency is the same for both.

Correct answer is (d)

Your score on this question is: 10.00

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



7.

Consider the following outline of a templated sorting function.

      template<class T>  void  sort( T a[], int n ) { ... }

For a given sorting algorithm S, which of the following is true about using this outline to implement S?



(a) It is a reasonable way to implement S.
(b) It is a poor choice since it does not work with linked lists.
(c) It is impossible since the algorithm cannot know how to compare two instances of type T.
(d) It is a poor choice since templates slow down sorting.

Correct answer is (a)

Your score on this question is: 10.00

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



8.

Consider the following outline of a templated array class.

      template<class T> class Array { ... }

Which of the following is true about using this outline to implement a general container class?



(a) It is impossible since the algorithm cannot know how to copy an instance of type T.
(b) It is a poor choice since templates slow down compilation.
(c) It is a poor choice since the type matching will slow down access at runtime.
(d) It is a reasonable way to implement such a class.

Correct answer is (d)

Your score on this question is: 10.00

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



9.

Consider the following outline of a templated array class.

      template<class T>  class Array { ... }

Which of the declarations below is in obvious error with respect to using such a class?



(a) Array<int> A(10);
(b) Array<int> A(10,0);
(c) Array<int> A<int>;
(d) Array<int> A;

Correct answer is (c)

Your score on this question is: 10.00

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



10.

Consider the following templated function.

  template<class Func>
  void mystery( Func f, int n, typename Func::result_type& x ) {
          for( int i = 0; i < n; i++ )
              x += f(i);
  }

If the first actual parameter of a call to mystery is a function object f that properly defines result_type and if n0 and x0 are the values of the second and third actual parameters, which of the following accurately describes the result of executing that call?



(a) x0+f(0)+f(1)+...+f(n0)is stored in x.
(b) f(0), f(1), ..., and f(n0) are stored in x in succession.
(c) f(0), f(1), ..., and f(n0-1) are stored in x in succession.
(d) x0+f(0)+f(1)+...+f(n0-1)is stored in x.

Correct answer is (d)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 90.00



Your performance was as follows:

1.
The purpose of function templates is to

(a) replace generic void* pointers in C
(b) increase the efficiency of various algorithms
(c) easily specify a family of operationally equivalent functions
(d) help the type-checker search for errors

Correct answer is (c)

Your score on this question is: 10.00

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



2.
What is the purpose of class templates?

(a) To easily specify a group of related classes
(b) To improve the portability of code
(c) To avoid the use of dangerous pointers
(d) To increase the efficiency of the class methods

Correct answer is (a)

Your score on this question is: 10.00

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



3.
What is the purpose of the keyword typename?

(a) To increase the efficiency of template compilation
(b) To point out to the compiler that whatever follows is the name of a type
(c) The same purpose as that of typedef
(d) To denote a generic type

Correct answer is (b)

Your score on this question is: 10.00

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



4.

Consider the following template specification.

      template<int n>  ...

In use, the template parameter n can be replaced by



(a) int values and int containers only
(b) arithmetic type values only
(c) any type of value
(d) int values only

Correct answer is (d)

Your score on this question is: 10.00

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



5.

Consider the following templated array copy function and arrays.

      template<class T>  void  copy( T a[], T b[], int n ) {
          for(int i = 0; i < n; i++ ) a[i] = b[i];
      }
      char   C[10], CC[10];
      int    I[10];
      float  F[10];

Which of the following calls to copy would produce a compile time error?



(a) copy( I, (int*)F, 10 );
(b) copy( I, F, 10 );
(c) copy( I, I, 10 );
(d) copy( C, CC, 10 );

Correct answer is (b)

Your score on this question is: 10.00

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



6.

Consider the following templated array copy function and arrays.

      template<class S, class T>  void  copy( S a[], T b[], int n ) {
          for(int i = 0; i < n; i++ ) a[i] = b[i];
      }
      char   C[10];
      int    I[10];
      float  F[10];

Which of the following calls to copy would produce a compile time error?

  1. copy( F, C, 10 );
  2. copy( I, C, 10 );
  3. copy( C, F, 10 );


(a) None
(b) I
(c) II
(d) III

Correct answer is (a)

Your score on this question is: 10.00

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



7.
Which of the following is true about the run-time efficiency of using templated functions versus using nontemplated functions?

(a) The run-time efficiency is better for templated functions.
(b) The run-time efficiency is the same for both.
(c) The run-time efficiency is slightly worse for templated functions.
(d) The run-time efficiency is much worse than for templated functions.

Correct answer is (b)

Your score on this question is: 10.00

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



8.

What, if anything, is wrong with the following function declaration?

      template<class A, class B>  A  f( B x );


(a) The parameter should be passed by reference.
(b) Nothing
(c) The compiler cannot determine B when f is called.
(d) The compiler cannot determine A when f is called.

Correct answer is (d)

Your score on this question is: 10.00

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



9.

If templates were removed from C++, which of the following would be true?

  1. Some algorithms could no longer be implemented.
  2. Any particular algorithm could still be implemented, but often less elegantly.
  3. Any particular algorithm could still be implemented, but the efficiency would often be catastrophically worse.


(a) II only
(b) None
(c) II and III
(d) I only

Correct answer is (b)

Your score on this question is: 10.00

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



10.

Consider the following templated function.

   template<class T> T Apply( T x, T (*ff)(T) ){ return ff(x); }

Which of the following is true concerning its use?



(a) The input function can be arbitrary, and the templated function returns the result of calling the second input on the first input.
(b) The input function can be arbitrary, and the templated function returns a pointer to the result of calling the second input on the first input.
(c) The input function must return the same type as its argument, and the templated function returns the result of calling the second input on the first input.
(d) The input function must return the same type as its argument, and the templated function returns a pointer to the result of calling the second input on the first input.

Correct answer is (c)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.
The purpose of function templates is to

(a) easily specify a family of operationally equivalent functions
(b) help the type-checker search for errors
(c) replace generic void* pointers in C
(d) increase the efficiency of various algorithms

Correct answer is (a)

Your score on this question is: 10.00

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



2.
What is the purpose of the keyword typename?

(a) The same purpose as that of typedef
(b) To increase the efficiency of template compilation
(c) To denote a generic type
(d) To point out to the compiler that whatever follows is the name of a type

Correct answer is (d)

Your score on this question is: 10.00

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



3.

Consider the following templated array copy function and arrays.

      template<class T>  void  copy( T a[], T b[], int n ) {
          for(int i = 0; i < n; i++ ) a[i] = b[i];
      }
      char   C[10], CC[10];
      int    I[10];
      float  F[10];

Which of the following calls to copy would produce a compile time error?



(a) copy( I, F, 10 );
(b) copy( C, CC, 10 );
(c) copy( I, (int*)F, 10 );
(d) copy( I, I, 10 );

Correct answer is (a)

Your score on this question is: 10.00

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



4.

Consider the following templated array copy function and arrays.

      template<class S, class T>  void  copy( S a[], T b[], int n ) {
          for(int i = 0; i < n; i++ ) a[i] = b[i];
      }
      char   C[10];
      int    I[10];
      float  F[10];

Which of the following calls to copy would produce a compile time error?

  1. copy( F, C, 10 );
  2. copy( I, C, 10 );
  3. copy( C, F, 10 );


(a) None
(b) III
(c) I
(d) II

Correct answer is (a)

Your score on this question is: 10.00

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



5.
Which of the following is true about compilation of a templated function or class?

(a) Templates are not handled during compilation.
(b) Compilation takes less time.
(c) Compilation takes much, much longer.
(d) Compilation takes slightly longer.

Correct answer is (d)

Your score on this question is: 10.00

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



6.

What, if anything, is wrong with the following function declaration?

      template<class A, class B>  A  f( B x );


(a) The compiler cannot determine B when f is called.
(b) Nothing
(c) The parameter should be passed by reference.
(d) The compiler cannot determine A when f is called.

Correct answer is (d)

Your score on this question is: 10.00

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



7.

If templates were removed from C++, which of the following would be true?

  1. Some algorithms could no longer be implemented.
  2. Any particular algorithm could still be implemented, but often less elegantly.
  3. Any particular algorithm could still be implemented, but the efficiency would often be catastrophically worse.


(a) II only
(b) II and III
(c) None
(d) I only

Correct answer is (c)

Your score on this question is: 10.00

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



8.

Consider the following outline of a templated array class.

      template<class T>  class Array { ... }

Which of the following declarations are in error with respect to using such a class?

  1. Array<Array<int> > A;
  2. Array<Array<int>*> A;
  3. Array<int**> A;


(a) None
(b) II only
(c) III only
(d) I only

Correct answer is (a)

Your score on this question is: 10.00

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



9.

Consider the following templated function.

   template<class T> T Apply( T x, T (*ff)(T) ){ return ff(x); }

Which of the following is true concerning its use?



(a) The input function can be arbitrary, and the templated function returns a pointer to the result of calling the second input on the first input.
(b) The input function can be arbitrary, and the templated function returns the result of calling the second input on the first input.
(c) The input function must return the same type as its argument, and the templated function returns a pointer to the result of calling the second input on the first input.
(d) The input function must return the same type as its argument, and the templated function returns the result of calling the second input on the first input.

Correct answer is (d)

Your score on this question is: 10.00

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



10.

Consider the following templated function.

  template<class Func>
  void mystery( Func f, int n, typename Func::result_type& x ) {
          for( int i = 0; i < n; i++ )
              x += f(i);
  }

If the first actual parameter of a call to mystery is a function object f that properly defines result_type and if n0 and x0 are the values of the second and third actual parameters, which of the following accurately describes the result of executing that call?



(a) f(0), f(1), ..., and f(n0) are stored in x in succession.
(b) x0+f(0)+f(1)+...+f(n0-1)is stored in x.
(c) x0+f(0)+f(1)+...+f(n0)is stored in x.
(d) f(0), f(1), ..., and f(n0-1) are stored in x in succession.

Correct answer is (b)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.
What is the purpose of class templates?

(a) To avoid the use of dangerous pointers
(b) To improve the portability of code
(c) To increase the efficiency of the class methods
(d) To easily specify a group of related classes

Correct answer is (d)

Your score on this question is: 10.00

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



2.

In a template definition

      template<class T>  ...

the template parameter T ranges over



(a) only built-in types
(b) only user-defined classes
(c) classes as well as structs
(d) all types

Correct answer is (d)

Your score on this question is: 10.00

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



3.

Consider the following template specification.

      template<int n>  ...

In use, the template parameter n can be replaced by



(a) int values only
(b) any type of value
(c) int values and int containers only
(d) arithmetic type values only

Correct answer is (a)

Your score on this question is: 10.00

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



4.

Consider the following templated array copy function and arrays.

      template<class T>  void  copy( T a[], T b[], int n ) {
          for(int i = 0; i < n; i++ ) a[i] = b[i];
      }
      char   C[10], CC[10];
      int    I[10];
      float  F[10];

Which of the following calls to copy would produce a compile time error?



(a) copy( I, (int*)F, 10 );
(b) copy( I, F, 10 );
(c) copy( I, I, 10 );
(d) copy( C, CC, 10 );

Correct answer is (b)

Your score on this question is: 10.00

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



5.
Which of the following is true about the run-time efficiency of using templated functions versus using nontemplated functions?

(a) The run-time efficiency is better for templated functions.
(b) The run-time efficiency is the same for both.
(c) The run-time efficiency is slightly worse for templated functions.
(d) The run-time efficiency is much worse than for templated functions.

Correct answer is (b)

Your score on this question is: 10.00

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



6.

Consider the following outline of a templated sorting function.

      template<class T>  void  sort( T a[], int n ) { ... }

For a given sorting algorithm S, which of the following is true about using this outline to implement S?



(a) It is a poor choice since templates slow down sorting.
(b) It is impossible since the algorithm cannot know how to compare two instances of type T.
(c) It is a reasonable way to implement S.
(d) It is a poor choice since it does not work with linked lists.

Correct answer is (c)

Your score on this question is: 10.00

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



7.

Consider the following outline of a templated array class.

      template<class T>  class Array { ... }

Which of the declarations below is in obvious error with respect to using such a class?



(a) Array<int> A(10,0);
(b) Array<int> A;
(c) Array<int> A(10);
(d) Array<int> A<int>;

Correct answer is (d)

Your score on this question is: 10.00

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



8.

Consider the following outline of a templated array class.

      template<class T>  class Array { ... }

Which of the following declarations are in error with respect to using such a class?

  1. Array<Array<int> > A;
  2. Array<Array<int>*> A;
  3. Array<int**> A;


(a) I only
(b) II only
(c) III only
(d) None

Correct answer is (d)

Your score on this question is: 10.00

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



9.

Consider the following templated function.

   template<class T> T Apply( T x, T (*ff)(T) ){ return ff(x); }

Which of the following is true concerning its use?



(a) The input function can be arbitrary, and the templated function returns a pointer to the result of calling the second input on the first input.
(b) The input function must return the same type as its argument, and the templated function returns the result of calling the second input on the first input.
(c) The input function must return the same type as its argument, and the templated function returns a pointer to the result of calling the second input on the first input.
(d) The input function can be arbitrary, and the templated function returns the result of calling the second input on the first input.

Correct answer is (b)

Your score on this question is: 10.00

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



10.

Consider the following templated function.

  template<class Func>
  void mystery( Func f, int n, typename Func::result_type& x ) {
          for( int i = 0; i < n; i++ )
              x += f(i);
  }

If the first actual parameter of a call to mystery is a function object f that properly defines result_type and if n0 and x0 are the values of the second and third actual parameters, which of the following accurately describes the result of executing that call?



(a) x0+f(0)+f(1)+...+f(n0)is stored in x.
(b) f(0), f(1), ..., and f(n0) are stored in x in succession.
(c) f(0), f(1), ..., and f(n0-1) are stored in x in succession.
(d) x0+f(0)+f(1)+...+f(n0-1)is stored in x.

Correct answer is (d)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.
Which of the following is true of inheritance?

(a) It is an important idea in Object Oriented Programming, but currently it is not implemented in C++.
(b) It protects data members from illegal access.
(c) It provides for the elegant construction of a new class from an existing class.
(d) It causes one type to behave like several types.

Correct answer is (c)

Your score on this question is: 10.00

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



2.
Which of the following is true of multiple inheritance?

(a) It provides for the elegant construction of a new class from existing classes.
(b) It causes one type to behave like several types.
(c) It is an important idea in Object-Oriented Programming, but currently it is not implemented in C++.
(d) It allows the application of inheritance over and over, producing deep hierarchies.

Correct answer is (a)

Your score on this question is: 10.00

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



3.
Polymorphism is a mechanism that is used in order to

(a) determine the type of an object dynamically at run time
(b) determine methods of a class based on its data members
(c) build new classes on top of existing ones
(d) protect data members from illegal access

Correct answer is (a)

Your score on this question is: 10.00

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



4.
All of the following are features of object-oriented programming EXCEPT

(a) inheritance
(b) encapsulation
(c) polymorphism
(d) garbage collection

Correct answer is (d)

Your score on this question is: 10.00

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



5.
In which of the following situations would private inheritance be a sound choice?

(a) When the base class is templated
(b) To derive a numerical array class from a general one
(c) To derive a stack from a general linked list class
(d) Whenever multiple inheritance is used

Correct answer is (c)

Your score on this question is: 10.00

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



6.
Which of the following is necessary in order to obtain polymorphic behavior in C++?

(a) Only instances of the base class are used.
(b) Multiple inheritance is avoided.
(c) Pointers or references are used with virtual functions.
(d) Templates are avoided.

Correct answer is (c)

Your score on this question is: 10.00

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



7.
What is the role of the destructor for the base class when an instance of a derived class goes out of scope?

(a) It will not be called and it cannot be called at such a time.
(b) It must be called by the user, unless the derived class uses dynamic memory (the heap).
(c) It is available to be called by the user to prevent the destructor for the derived class from being called..
(d) It is called automatically.

Correct answer is (d)

Your score on this question is: 0.00

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



8.

Consider the following inheritance declarations.

    class Base { virtual  void f(int); virtual void f(float); };
    class Derived: public Base  { void f(int); };
    Derived  D;
    Base     B, *p = &D;

In the context of these declarations, the two functions that are used in the two calls D.f(3.1415); and p-f(3.1415); are, respectively,



(a) Base::f(double) and Base::f(double)
(b) Derived::f(int) and Base::f(double)
(c) Base::f(double) and Derived::f(int)
(d) Derived::f(int) and Derived::f(int)

Correct answer is (d)

Your score on this question is: 10.00

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



9.
The proper tool for writing a linked list that can have some elements with ints and other elements with floats is the use of

(a) unions
(b) casting of ints to floats and the use of a simple list
(c) templates
(d) inheritance

Correct answer is (d)

Your score on this question is: 0.00

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



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

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

Correct answer is (d)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 80.00



Your performance was as follows:

1.
Which of the following is true of inheritance?

(a) It causes one type to behave like several types.
(b) It protects data members from illegal access.
(c) It is an important idea in Object Oriented Programming, but currently it is not implemented in C++.
(d) It provides for the elegant construction of a new class from an existing class.

Correct answer is (d)

Your score on this question is: 10.00

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



2.
Polymorphism is a mechanism that is used in order to

(a) determine methods of a class based on its data members
(b) protect data members from illegal access
(c) build new classes on top of existing ones
(d) determine the type of an object dynamically at run time

Correct answer is (d)

Your score on this question is: 10.00

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



3.
What is composition?

(a) It is the same as polymorphism.
(b) It is a method to build new classes on top of existing ones.
(c) It is the inclusion of one class in another as a data member.
(d) It is an important idea in Object Oriented Programming, but currently it is not implemented in C++.

Correct answer is (c)

Your score on this question is: 10.00

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



4.
All of the following are features of object-oriented programming EXCEPT

(a) polymorphism
(b) encapsulation
(c) garbage collection
(d) inheritance

Correct answer is (c)

Your score on this question is: 10.00

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



5.
In which of the following situations would private inheritance be a sound choice?

(a) To derive a stack from a general linked list class
(b) When the base class is templated
(c) Whenever multiple inheritance is used
(d) To derive a numerical array class from a general one

Correct answer is (a)

Your score on this question is: 10.00

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



6.
Under what circumstances will a member function in C++ display polymorphic behavior?

(a) Always
(b) If and only if the class has multiple inheritance
(c) If and only if the function is explicitly declared to be virtual
(d) If and only if the class is not templated

Correct answer is (c)

Your score on this question is: 10.00

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



7.
What is the role of the destructor for the base class when an instance of a derived class goes out of scope?

(a) It is available to be called by the user to prevent the destructor for the derived class from being called..
(b) It will not be called and it cannot be called at such a time.
(c) It is called automatically.
(d) It must be called by the user, unless the derived class uses dynamic memory (the heap).

Correct answer is (c)

Your score on this question is: 10.00

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



8.

Consider the following inheritance declarations.

    class Base { virtual  void f(int); virtual void f(float); };
    class Derived: public Base  { void f(int); };
    Derived  D;
    Base     B, *p = &D;

In the context of these declarations, the two functions that are used in the two calls D.f(3.1415); and p-f(3.1415); are, respectively,



(a) Derived::f(int) and Base::f(double)
(b) Base::f(double) and Derived::f(int)
(c) Base::f(double) and Base::f(double)
(d) Derived::f(int) and Derived::f(int)

Correct answer is (d)

Your score on this question is: 10.00

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



9.
The purpose of initializers in a constructor is to

(a) make sure all data members are initialized
(b) avoid the copy constructor
(c) avoid assignments and use copy constructors directly
(d) make it easier to implement value semantics

Correct answer is (c)

Your score on this question is: 0.00

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



10.
Every class that is supposed to behave like a built-in type must overload which operator?

(a) The comma operator
(b) The call operator
(c) The assignment operator
(d) The output operator

Correct answer is (d)

Your score on this question is: 0.00

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



Go to top of assessment.

Total score: 80.00



Your performance was as follows:

1.
Polymorphism is a mechanism that is used in order to

(a) determine the type of an object dynamically at run time
(b) protect data members from illegal access
(c) build new classes on top of existing ones
(d) determine methods of a class based on its data members

Correct answer is (a)

Your score on this question is: 10.00

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



2.
What is composition?

(a) It is a method to build new classes on top of existing ones.
(b) It is an important idea in Object Oriented Programming, but currently it is not implemented in C++.
(c) It is the inclusion of one class in another as a data member.
(d) It is the same as polymorphism.

Correct answer is (c)

Your score on this question is: 10.00

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



3.
In which of the following situations would private inheritance be a sound choice?

(a) Whenever multiple inheritance is used
(b) When the base class is templated
(c) To derive a stack from a general linked list class
(d) To derive a numerical array class from a general one

Correct answer is (c)

Your score on this question is: 10.00

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



4.
Under what circumstances will a member function in C++ display polymorphic behavior?

(a) If and only if the class has multiple inheritance
(b) If and only if the class is not templated
(c) If and only if the function is explicitly declared to be virtual
(d) Always

Correct answer is (c)

Your score on this question is: 10.00

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



5.

Consider the following inheritance declarations.

      class Base    { public: int x; private int y; };
      class Derived: public Base  { public: int z; };
      Derived  D;

Under these declarations, which of the following statements, if any, will fail to compile?



(a) D.y = 555;
(b) D.z = 555;
(c) D.x = 555;
(d) None

Correct answer is (a)

Your score on this question is: 10.00

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



6.

Consider the following inheritance declarations.

    class Base { virtual  void f(int); virtual void f(float); };
    class Derived: public Base  { void f(int); };
    Derived  D;
    Base     B, *p = &D;

In the context of these declarations, the two functions that are used in the two calls D.f(3.1415); and p-f(3.1415); are, respectively,



(a) Base::f(double) and Derived::f(int)
(b) Derived::f(int) and Derived::f(int)
(c) Derived::f(int) and Base::f(double)
(d) Base::f(double) and Base::f(double)

Correct answer is (b)

Your score on this question is: 10.00

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



7.
Which of the following is true about a class without a (user-defined) constructor?

(a) It may have a destructor, but might not.
(b) It must have a destructor.
(c) It cannot have a destructor.
(d) It cannot have an assignment operator.

Correct answer is (a)

Your score on this question is: 10.00

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



8.
Every class that is supposed to behave like a built-in type must overload which operator?

(a) The comma operator
(b) The output operator
(c) The assignment operator
(d) The call operator

Correct answer is (b)

Your score on this question is: 10.00

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



9.
The proper tool for writing a linked list that can have some elements with ints and other elements with floats is the use of

(a) templates
(b) unions
(c) casting of ints to floats and the use of a simple list
(d) inheritance

Correct answer is (d)

Your score on this question is: 10.00

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



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

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

Correct answer is (c)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.
Which of the following is true of multiple inheritance?

(a) It provides for the elegant construction of a new class from existing classes.
(b) It causes one type to behave like several types.
(c) It is an important idea in Object-Oriented Programming, but currently it is not implemented in C++.
(d) It allows the application of inheritance over and over, producing deep hierarchies.

Correct answer is (a)

Your score on this question is: 10.00

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



2.
Polymorphism is a mechanism that is used in order to

(a) determine methods of a class based on its data members
(b) protect data members from illegal access
(c) build new classes on top of existing ones
(d) determine the type of an object dynamically at run time

Correct answer is (d)

Your score on this question is: 10.00

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



3.
Inheritance is an important feature of C++ because

(a) it can often replace templates
(b) it makes type-checking much easier
(c) it greatly increases efficiency
(d) it is a powerful code reuse mechanism

Correct answer is (d)

Your score on this question is: 10.00

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



4.
Which of the following is necessary in order to obtain polymorphic behavior in C++?

(a) Multiple inheritance is avoided.
(b) Templates are avoided.
(c) Only instances of the base class are used.
(d) Pointers or references are used with virtual functions.

Correct answer is (d)

Your score on this question is: 10.00

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



5.

Consider the following inheritance declarations.

      class Base    { public: int x; private int y; };
      class Derived: public Base  { public: int z; };
      Derived  D;

Under these declarations, which of the following statements, if any, will fail to compile?



(a) D.x = 555;
(b) D.y = 555;
(c) D.z = 555;
(d) None

Correct answer is (b)

Your score on this question is: 10.00

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



6.

Consider the following inheritance declarations.

    class Base { virtual  void f(int); virtual void f(float); };
    class Derived: public Base  { void f(int); };
    Derived  D;
    Base     B, *p = &D;

In the context of these declarations, the two functions that are used in the two calls D.f(3.1415); and p-f(3.1415); are, respectively,



(a) Base::f(double) and Base::f(double)
(b) Derived::f(int) and Base::f(double)
(c) Derived::f(int) and Derived::f(int)
(d) Base::f(double) and Derived::f(int)

Correct answer is (c)

Your score on this question is: 10.00

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



7.
The purpose of initializers in a constructor is to

(a) make it easier to implement value semantics
(b) make sure all data members are initialized
(c) avoid assignments and use copy constructors directly
(d) avoid the copy constructor

Correct answer is (c)

Your score on this question is: 10.00

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



8.
Every class that is supposed to behave like a built-in type must overload which operator?

(a) The output operator
(b) The comma operator
(c) The call operator
(d) The assignment operator

Correct answer is (a)

Your score on this question is: 10.00

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



9.
The proper tool for writing an array class whose instances can have some elements with ints and other elements with floats is the use of

(a) templates
(b) unions
(c) casting
(d) inheritance

Correct answer is (a)

Your score on this question is: 0.00

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



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

(a) A linked list class should not have a copy constructor.
(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) It should copy only the list header, and not the nodes.

Correct answer is (c)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 90.00



Your performance was as follows:

1.
Which of the following is true of multiple inheritance?

(a) It allows the application of inheritance over and over, producing deep hierarchies.
(b) It is an important idea in Object-Oriented Programming, but currently it is not implemented in C++.
(c) It provides for the elegant construction of a new class from existing classes.
(d) It causes one type to behave like several types.

Correct answer is (c)

Your score on this question is: 10.00

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



2.
Inheritance is an important feature of C++ because

(a) it is a powerful code reuse mechanism
(b) it greatly increases efficiency
(c) it makes type-checking much easier
(d) it can often replace templates

Correct answer is (a)

Your score on this question is: 10.00

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



3.
In which of the following situations would private inheritance be a sound choice?

(a) To derive a numerical array class from a general one
(b) When the base class is templated
(c) Whenever multiple inheritance is used
(d) To derive a stack from a general linked list class

Correct answer is (d)

Your score on this question is: 10.00

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



4.
Which of the following is necessary in order to obtain polymorphic behavior in C++?

(a) Templates are avoided.
(b) Only instances of the base class are used.
(c) Pointers or references are used with virtual functions.
(d) Multiple inheritance is avoided.

Correct answer is (c)

Your score on this question is: 10.00

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



5.
Under what circumstances will a member function in C++ display polymorphic behavior?

(a) Always
(b) If and only if the class is not templated
(c) If and only if the function is explicitly declared to be virtual
(d) If and only if the class has multiple inheritance

Correct answer is (c)

Your score on this question is: 10.00

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



6.
What is the role of the destructor for the base class when an instance of a derived class goes out of scope?

(a) It will not be called and it cannot be called at such a time.
(b) It must be called by the user, unless the derived class uses dynamic memory (the heap).
(c) It is called automatically.
(d) It is available to be called by the user to prevent the destructor for the derived class from being called..

Correct answer is (c)

Your score on this question is: 10.00

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



7.

Consider the following inheritance declarations.

    class Base { virtual  void f(int); virtual void f(float); };
    class Derived: public Base  { void f(int); };
    Derived  D;
    Base     B, *p = &D;

In the context of these declarations, the two functions that are used in the two calls D.f(3.1415); and p-f(3.1415); are, respectively,



(a) Base::f(double) and Base::f(double)
(b) Derived::f(int) and Base::f(double)
(c) Derived::f(int) and Derived::f(int)
(d) Base::f(double) and Derived::f(int)

Correct answer is (c)

Your score on this question is: 10.00

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



8.
Every class that is supposed to behave like a built-in type must overload which operator?

(a) The comma operator
(b) The output operator
(c) The assignment operator
(d) The call operator

Correct answer is (b)

Your score on this question is: 10.00

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



9.
The proper tool for writing a linked list that can have some elements with ints and other elements with floats is the use of

(a) inheritance
(b) templates
(c) unions
(d) casting of ints to floats and the use of a simple list

Correct answer is (a)

Your score on this question is: 10.00

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



10.
The proper tool for writing an array class whose instances can have some elements with ints and other elements with floats is the use of

(a) inheritance
(b) templates
(c) casting
(d) unions

Correct answer is (b)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



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



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



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



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


Family Name: LAM
Given Name: Ka Lee
Login: 50336714
E-mail: 50336714@cityu.edu.hk
Status: Enrolled

Assessment Name: Multiple Choice Quiz 6
Instance: 3

Section: CITYU-L09
During: Fall 2002

For course: Data Structures and Algorithms
(DCO20105)

Corresponding to: SSD5
At: City University of Hong Kong



Your performance was as follows:


Total score: 80.00


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

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

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

(a) To avoid templates and inheritance
(b) To use less memory
(c) To improve efficiency
(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



3.
A recursive function is one that

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

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 all the data structures used
(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 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



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

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



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) A pseudo-random number between 1 and n
(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) The logarithm of the input

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



8.

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) f(x)regardless of the value of n
(c) fn(x)
(d) f(x + n)

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



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

Correct answer is (a)

Your score on this question is: 0.00

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



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

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

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



Go to top of assessment.

Total score: 80.00



Your performance was as follows:

1.
What is the asymptotic running time of bubble sort on an input array with length n?

(a) O(n log n)
(b) O(n2)
(c) O(n)
(d) O(2n)

Correct answer is (b)

Your score on this question is: 10.00

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



2.
Which of the following statements about insertion sort is true asymptotically?

(a) Insertion sort is faster than merge sort, but consumes less memory.
(b) Insertion sort is slower than merge sort, and consumes more memory.
(c) Insertion sort is slower than merge sort, but consumes less memory.
(d) Insertion sort is slower than merge sort, and consumes about the same memory.

Correct answer is (c)

Your score on this question is: 10.00

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



3.

Consider the following recursive definition of a function f.

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

The asymptotic running time of the call f(n) is



(a) O(n log n)
(b) O(n)
(c) O(log n)
(d) O(n2)

Correct answer is (c)

Your score on this question is: 10.00

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



4.

Consider the following recursive definition of a function f.

int  f(int  n)
{
  if (n == 0) return 1;
  else return  f(n >> 1);
}

The asymptotic running time of the call f(n) is



(a) O(n)
(b) O(n2)
(c) O(n log n)
(d) O(log n)

Correct answer is (d)

Your score on this question is: 10.00

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



5.

Consider the following definition of a recursive function, power, that will perform exponentiation.

      int  power( int b, int e )
      {
        if( e == 0 ) return 1;
        if( e % 2 = 0 ) return  power( b * b, e/2 ); 
        return  b * power( b * b, e/2 );
      }

Asymptotically in terms of the exponent e, the number of calls to power that occur as a result of the call power(b,e) is



(a) linear
(b) quadratic
(c) exponential
(d) logarithmic

Correct answer is (d)

Your score on this question is: 10.00

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



6.
Using the standard gradeschool method, what is the asymptotic running time of multiplying two numbers that are both n digits long?

(a) 2n
(b) n3
(c) n
(d) n2

Correct answer is (d)

Your score on this question is: 10.00

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



7.
Using the standard gradeschool method, what is the asymptotic running time of adding two numbers that are both n digits long?

(a) n3
(b) n
(c) 2n
(d) n2

Correct answer is (b)

Your score on this question is: 10.00

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



8.

Consider the following code fragment.

      for( int i = 0; i < n; i++ )
            for( int j = 0; j < n; j++ )
                  for( int k = 0; k < n; k++ ) body;

If body executes in O(1) time, then the asymptotic running time of this code fragment is



(a) O(n3)
(b) O(2n)
(c) O(n2)
(d) O(n)

Correct answer is (a)

Your score on this question is: 10.00

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



9.

Consider the following code fragment.

    for( int i = 0; i < n; i++ )
            for( int j = 0; j < n/5; j++ ) body;

If body executes in O(1) time, then the asymptotic running time of this code fragment is



(a) O(n log n)
(b) O(n)
(c) O(n2)
(d) O(n3)

Correct answer is (c)

Your score on this question is: 0.00

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



10.

Consider the following code fragment.

for( int i = 0; i < n; i += 2 )
  for(int  j = i; j > 0; j -= 3 ) body

If body executes in O(1) time, then the asymptotic running time of this code fragment is



(a) O(n3)
(b) O(n2)
(c) O(n log n)
(d) O(n)

Correct answer is (b)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 90.00



Your performance was as follows:

1.
What is the asymptotic running time of insertion sort on an input array with length n?

(a) n
(b) n log n
(c) 2n
(d) n2

Correct answer is (d)

Your score on this question is: 10.00

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



2.
Which of the following statements about insertion sort is true asymptotically?

(a) Insertion sort is slower than merge sort, and consumes more memory.
(b) Insertion sort is slower than merge sort, and consumes about the same memory.
(c) Insertion sort is slower than merge sort, but consumes less memory.
(d) Insertion sort is faster than merge sort, but consumes less memory.

Correct answer is (c)

Your score on this question is: 10.00

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



3.

Consider the following code fragment.

      for( int i = 1; i < n; i *= 2 ) body;

If body executes in O(1) time, then the asymptotic running time of the code fragment above is



(a) O(n2)
(b) O(n log n)
(c) O(log n)
(d) O(n)

Correct answer is (c)

Your score on this question is: 0.00

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



4.

Consider the following recursive definition of a function f.

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

The asymptotic running time of the call f(n) is



(a) O(log n)
(b) O(n2)
(c) O(n log n)
(d) O(n)

Correct answer is (a)

Your score on this question is: 10.00

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



5.

Consider the following recursive definition of a function f.

int  f(int  n)
{
  if (n == 0) return 1;
  else return  f(n >> 1);
}

The asymptotic running time of the call f(n) is



(a) O(n)
(b) O(n log n)
(c) O(log n)
(d) O(n2)

Correct answer is (c)

Your score on this question is: 10.00

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



6.

Consider the following definition of a recursive function, power, that will perform exponentiation.

      int  power( int b, int e )
      {
        if( e == 0 ) return 1;
        if( e % 2 = 0 ) return  power( b * b, e/2 ); 
        return  b * power( b * b, e/2 );
      }

Asymptotically in terms of the exponent e, the number of calls to power that occur as a result of the call power(b,e) is



(a) linear
(b) exponential
(c) quadratic
(d) logarithmic

Correct answer is (d)

Your score on this question is: 10.00

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



7.

Consider the following code fragment.

      for( int i = 0; i < n; i++ )
            for( int j = 0; j < n; j++ )
                  for( int k = 0; k < n; k++ ) body;

If body executes in O(1) time, then the asymptotic running time of this code fragment is



(a) O(n2)
(b) O(n3)
(c) O(2n)
(d) O(n)

Correct answer is (b)

Your score on this question is: 10.00

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



8.

Consider the following code fragment.

    for( int i = 0; i < n; i += 2 )
            for( int j = 0; j < n; j += 3 )
                  for( int k = 0; k < n; k += 4 ) body;

If body executes in O(1) time, then the asymptotic running time of this code fragment is



(a) O(n2)
(b) O(n)
(c) O(n log n)
(d) O(n3)

Correct answer is (d)

Your score on this question is: 10.00

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



9.

Consider the following code fragment.

    for( int i = 0; i < n; i++ )
            for( int j = 0; j < n/5; j++ ) body;

If body executes in O(1) time, then the asymptotic running time of this code fragment is



(a) O(n2)
(b) O(n3)
(c) O(n)
(d) O(n log n)

Correct answer is (a)

Your score on this question is: 10.00

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



10.

Consider the following code fragment.

for( int i = 0; i < n; i += 2 )
  for(int  j = i; j > 0; j -= 3 ) body

If body executes in O(1) time, then the asymptotic running time of this code fragment is



(a) O(n)
(b) O(n log n)
(c) O(n2)
(d) O(n3)

Correct answer is (c)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 90.00



Your performance was as follows:

1.
What is the asymptotic running time of insertion sort on an input array with length n?

(a) n2
(b) n
(c) 2n
(d) n log n

Correct answer is (a)

Your score on this question is: 10.00

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



2.
Which of the following statements about insertion sort is true asymptotically?

(a) Insertion sort is slower than merge sort, but consumes less memory.
(b) Insertion sort is slower than merge sort, and consumes more memory.
(c) Insertion sort is faster than merge sort, but consumes less memory.
(d) Insertion sort is slower than merge sort, and consumes about the same memory.

Correct answer is (a)

Your score on this question is: 10.00

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



3.

Consider the following code fragment.

      for( int i = n; i > 0; i /= 2 ) body;

If body executes in O(1) time, then the asymptotic running time of the code fragment above is



(a) O(n)
(b) O(n log n)
(c) O(log n)
(d) O(n2)

Correct answer is (c)

Your score on this question is: 10.00

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



4.

Consider the following code fragment.

      for( int i = 1; i < n; i *= 2 ) body;

If body executes in O(1) time, then the asymptotic running time of the code fragment above is



(a) O(n)
(b) O(n2)
(c) O(log n)
(d) O(n log n)

Correct answer is (c)

Your score on this question is: 10.00

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



5.

Consider the following recursive definition of a function f.

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

The asymptotic running time of the call f(n) is



(a) O(n log n)
(b) O(log n)
(c) O(n2)
(d) O(n)

Correct answer is (b)

Your score on this question is: 10.00

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



6.
Using the standard gradeschool method, what is the asymptotic running time of multiplying two numbers that are both n digits long?

(a) n3
(b) n2
(c) n
(d) 2n

Correct answer is (b)

Your score on this question is: 10.00

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



7.
Using the standard gradeschool method, what is the asymptotic running time of adding two numbers that are both n digits long?

(a) n3
(b) n
(c) n2
(d) 2n

Correct answer is (b)

Your score on this question is: 10.00

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



8.
What is the asymptotic running time of merge sort with an input array of length n?

(a) O(2n)
(b) O(n2)
(c) O(n)
(d) O(n log n)

Correct answer is (d)

Your score on this question is: 10.00

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



9.

Consider the following code fragment.

    for( int i = 0; i < n; i += 2 )
            for( int j = 0; j < n; j += 3 )
                  for( int k = 0; k < n; k += 4 ) body;

If body executes in O(1) time, then the asymptotic running time of this code fragment is



(a) O(n log n)
(b) O(n2)
(c) O(n)
(d) O(n3)

Correct answer is (d)

Your score on this question is: 10.00

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



10.

Consider the following code fragment.

for( int i = 0; i < n; i += 2 )
  for(int  j = i; j > 0; j -= 3 ) body

If body executes in O(1) time, then the asymptotic running time of this code fragment is



(a) O(n log n)
(b) O(n)
(c) O(n2)
(d) O(n3)

Correct answer is (c)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.
What is the asymptotic running time of bubble sort on an input array with length n?

(a) O(n)
(b) O(n log n)
(c) O(2n)
(d) O(n2)

Correct answer is (d)

Your score on this question is: 10.00

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



2.
Which of the following statements about insertion sort is true asymptotically?

(a) Insertion sort is slower than merge sort, and consumes about the same memory.
(b) Insertion sort is slower than merge sort, but consumes less memory.
(c) Insertion sort is faster than merge sort, but consumes less memory.
(d) Insertion sort is slower than merge sort, and consumes more memory.

Correct answer is (b)

Your score on this question is: 10.00

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



3.

Consider the following code fragment.

      for( int i = n; i > 0; i /= 2 ) body;

If body executes in O(1) time, then the asymptotic running time of the code fragment above is



(a) O(log n)
(b) O(n2)
(c) O(n log n)
(d) O(n)

Correct answer is (a)

Your score on this question is: 10.00

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



4.

Consider the following code fragment.

      for( int i = 1; i < n; i *= 2 ) body;

If body executes in O(1) time, then the asymptotic running time of the code fragment above is



(a) O(n log n)
(b) O(n2)
(c) O(n)
(d) O(log n)

Correct answer is (d)

Your score on this question is: 10.00

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



5.

Consider the following recursive definition of a function f.

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

The asymptotic running time of the call f(n) is



(a) O(n2)
(b) O(log n)
(c) O(n)
(d) O(n log n)

Correct answer is (b)

Your score on this question is: 10.00

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



6.

Consider the following definition of a recursive function, power, that will perform exponentiation.

      int  power( int b, int e )
      {
        if( e == 0 ) return 1;
        if( e % 2 = 0 ) return  power( b * b, e/2 ); 
        return  b * power( b * b, e/2 );
      }

Asymptotically in terms of the exponent e, the number of calls to power that occur as a result of the call power(b,e) is



(a) linear
(b) logarithmic
(c) exponential
(d) quadratic

Correct answer is (b)

Your score on this question is: 10.00

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



7.
Using the standard gradeschool method, what is the asymptotic running time of multiplying two numbers that are both n digits long?

(a) n
(b) n2
(c) 2n
(d) n3

Correct answer is (b)

Your score on this question is: 10.00

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



8.
Using the standard gradeschool method, what is the asymptotic running time of adding two numbers that are both n digits long?

(a) n
(b) 2n
(c) n2
(d) n3

Correct answer is (a)

Your score on this question is: 10.00

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



9.
What is the asymptotic running time of merge sort with an input array of length n?

(a) O(n2)
(b) O(2n)
(c) O(n log n)
(d) O(n)

Correct answer is (c)

Your score on this question is: 10.00

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



10.

Consider the following code fragment.

for( int i = 0; i < n; i += 2 )
  for(int  j = i; j > 0; j -= 3 ) body

If body executes in O(1) time, then the asymptotic running time of this code fragment is



(a) O(n)
(b) O(n3)
(c) O(n2)
(d) O(n log n)

Correct answer is (c)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.
What is the asymptotic running time of bubble sort on an input array with length n?

(a) O(n log n)
(b) O(n2)
(c) O(2n)
(d) O(n)

Correct answer is (b)

Your score on this question is: 10.00

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



2.
Which of the following statements about insertion sort is true asymptotically?

(a) Insertion sort is faster than merge sort, but consumes less memory.
(b) Insertion sort is slower than merge sort, and consumes about the same memory.
(c) Insertion sort is slower than merge sort, but consumes less memory.
(d) Insertion sort is slower than merge sort, and consumes more memory.

Correct answer is (c)

Your score on this question is: 10.00

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



3.

Consider the following code fragment.

      for( int i = n; i > 0; i /= 2 ) body;

If body executes in O(1) time, then the asymptotic running time of the code fragment above is



(a) O(log n)
(b) O(n2)
(c) O(n)
(d) O(n log n)

Correct answer is (a)

Your score on this question is: 10.00

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



4.

Consider the following code fragment.

      for( int i = 1; i < n; i *= 2 ) body;

If body executes in O(1) time, then the asymptotic running time of the code fragment above is



(a) O(n2)
(b) O(n log n)
(c) O(n)
(d) O(log n)

Correct answer is (d)

Your score on this question is: 10.00

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



5.

Consider the following recursive definition of a function f.

int  f(int  n)
{
  if (n == 0) return 1;
  else return  f(n >> 1);
}

The asymptotic running time of the call f(n) is



(a) O(n)
(b) O(n log n)
(c) O(n2)
(d) O(log n)

Correct answer is (d)

Your score on this question is: 10.00

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



6.

Consider the following definition of a recursive function, power, that will perform exponentiation.

      int  power( int b, int e )
      {
        if( e == 0 ) return 1;
        if( e % 2 = 0 ) return  power( b * b, e/2 ); 
        return  b * power( b * b, e/2 );
      }

Asymptotically in terms of the exponent e, the number of calls to power that occur as a result of the call power(b,e) is



(a) logarithmic
(b) quadratic
(c) linear
(d) exponential

Correct answer is (a)

Your score on this question is: 10.00

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



7.
Using the standard gradeschool method, what is the asymptotic running time of multiplying two numbers that are both n digits long?

(a) n
(b) n3
(c) 2n
(d) n2

Correct answer is (d)

Your score on this question is: 10.00

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



8.
What is the asymptotic running time of merge sort with an input array of length n?

(a) O(n)
(b) O(n2)
(c) O(n log n)
(d) O(2n)

Correct answer is (c)

Your score on this question is: 10.00

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



9.

Consider the following code fragment.

      for( int i = 0; i < n; i++ )
            for( int j = 0; j < n; j++ )
                  for( int k = 0; k < n; k++ ) body;

If body executes in O(1) time, then the asymptotic running time of this code fragment is



(a) O(n3)
(b) O(n)
(c) O(n2)
(d) O(2n)

Correct answer is (a)

Your score on this question is: 10.00

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



10.

Consider the following code fragment.

for( int i = 0; i < n; i += 2 )
  for(int  j = i; j > 0; j -= 3 ) body

If body executes in O(1) time, then the asymptotic running time of this code fragment is



(a) O(n)
(b) O(n log n)
(c) O(n3)
(d) O(n2)

Correct answer is (d)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.
Access to ranges of elements in an STL container is typically handled by

(a) iterators
(b) pointers
(c) suitable access member functions
(d) references

Correct answer is (a)

Your score on this question is: 10.00

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



2.

Consider the execution of the following.

   list<int>  A(10);

Which of the following accurately describes what is created?



(a) A linked list of 10 ints, with each element initially containing random values.
(b) 10 linked list of ints, all initially empty.
(c) A linked list of 10 ints, with each element initially 0.
(d) An empty linked list of ints, but reserves memory for 10 entries.

Correct answer is (c)

Your score on this question is: 0.00

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



3.

Consider the execution of the following.

    list<int>  A(10,20);

Which of the following accurately describes what is created?



(a) A linked list of size 10, each containing 10 arrays of ints of size 20
(b) An array of size 20 of linked list, each containing 20 ints
(c) a linked list of 10 linked lists, each containing 20 ints
(d) A linked list of 10 ints, with each element initially 20

Correct answer is (d)

Your score on this question is: 10.00

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



4.

Consider the following code fragment.

      stack<int>  S;
      S.push(123);
      S.push(456);

Now consider the following statement.

   cout << S.pop() << endl;

Which of the following most accurately describes what goes wrong when that statement is executed?



(a) An execution error occurs because pop() is a private member function.
(b) pop() requires an argument.
(c) An execution error occurs because an STL stack has no member function pop().
(d) pop() does not return a value.

Correct answer is (d)

Your score on this question is: 10.00

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



5.

Execution of the code fragment

    stack<int,vector<int> >  S;

does which of the following?



(a) Creates a stack of ints, based on an integer vector
(b) Creates a vector of integer stacks
(c) Creates a stack of integer vectors
(d) Produces an execution error

Correct answer is (a)

Your score on this question is: 10.00

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



6.

For an STL iterator it, execution of the statement

    ++it;

does which of the following?



(a) Advances the iterator to the next item.
(b) Post-increments the item to which the iterator points.
(c) Pre-increments the item to which the iterator points.
(d)

Increase by 1 the size of the container pointed to by it.


Correct answer is (a)

Your score on this question is: 0.00

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



7.

Consider the following code fragment.

      li    st<int>::const_iterator  it;
      for(  it = L.begin(); it != L.end(); ++it )
      *it = 0;

What is syntactically wrong with this fragment?



(a) The traversal using a const iterator
(b) The use of the prefix increment operator on a const iterator.
(c) Nothing
(d) The assignment using a const iterator

Correct answer is (d)

Your score on this question is: 10.00

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



8.

The STL contains a general purpose search function:

      find( first, last, x );

What does find return if it finds item x?



(a) A pointer pointing to x
(b) An iterator pointing to x
(c) A reference to x
(d) The Boolean value true

Correct answer is (b)

Your score on this question is: 10.00

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



9.

The STL contains a general purpose search function:

      find( first, last, x );

What does find return if it fails to find item x?



(a) The Boolean value false
(b) A NULL pointer
(c) An iterator equal to begin
(d) An iterator equal to last

Correct answer is (d)

Your score on this question is: 10.00

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



10.

Consider the following statement using the STL sort() routine.

      sort( A.begin(), A.end(), f );

Which of the following most accurately describes the result of executing this statement?



(a) Container A is sorted using sorting algorithm f.
(b) Container A is sorted using the function f for assignments.
(c) Container A is sorted by applying function f to its elements.
(d) Container A is sorted using the Boolean valued function f for comparisons.

Correct answer is (d)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 80.00



Your performance was as follows:

1.
Access to ranges of elements in an STL container is typically handled by

(a) iterators
(b) references
(c) pointers
(d) suitable access member functions

Correct answer is (a)

Your score on this question is: 10.00

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



2.

Execution of the code fragment

    list<int>  A(10);

does which of the following?



(a) Creates a linked list of 10 ints, with each element initially 0.
(b) Creates a linked list of 10 ints, with each element initially containing random values.
(c) Creates an empty linked list of ints, but reserves memory for 10 entries
(d) Creates 10 linked list of ints, all initially empty.

Correct answer is (a)

Your score on this question is: 10.00

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



3.

Consider the following code fragment.

      stack<int>  S;
      S.push(123);
      S.push(456);

Now consider the following statement.

   cout << S.pop() << endl;

Which of the following most accurately describes what goes wrong when that statement is executed?



(a) An execution error occurs because pop() is a private member function.
(b) pop() requires an argument.
(c) An execution error occurs because an STL stack has no member function pop().
(d) pop() does not return a value.

Correct answer is (d)

Your score on this question is: 10.00

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



4.

Execution of the code fragment

    stack<int,vector<int> >  S;

does which of the following?



(a) Creates a stack of integer vectors
(b) Creates a vector of integer stacks
(c) Produces an execution error
(d) Creates a stack of ints, based on an integer vector

Correct answer is (d)

Your score on this question is: 10.00

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



5.

Execution of the code fragment

    stack<int,list<int> >  S;

does which of the following?



(a) Creates a stack of integer lists
(b) Creates a list of integer stacks
(c) Creates a stack of ints, based on an integer list
(d) Produces an execution error

Correct answer is (c)

Your score on this question is: 10.00

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



6.

For an STL iterator it, execution of the statement

    ++it;

does which of the following?



(a) Advances the iterator to the next item.
(b) Post-increments the item to which the iterator points.
(c)

Increase by 1 the size of the container pointed to by it.


(d) Pre-increments the item to which the iterator points.

Correct answer is (a)

Your score on this question is: 10.00

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



7.

For an STL iterator it and an STL container A, the expression

      it != A.end()

is used for which of the following purposes?



(a) To test whether the iterator points to the last element of A
(b) To test whether the iterator is at the one-past-the-end position
(c) To test whether the iterator points at some element of A
(d) To reset the iterator to the beginning of A

Correct answer is (b)

Your score on this question is: 0.00

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



8.
What is the difference between a bidirectional iterator (BDI) and a random access iterator (RAI)?

(a) They only differ with respect to efficiency, but they support the same operations.
(b) The RAI can jump in arbitrary increments and decrements; a BDI can only move in increments/decrements of one.
(c) A RAI supports post-increment, but a BDI does not.
(d) A BDI cannot be moved backwards, but a RAI can.

Correct answer is (b)

Your score on this question is: 10.00

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



9.

The STL contains a general purpose search function:

      find( first, last, x );

What does find return if it finds item x?



(a) The Boolean value true
(b) A pointer pointing to x
(c) An iterator pointing to x
(d) A reference to x

Correct answer is (c)

Your score on this question is: 10.00

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



10.

The STL contains a general purpose search function:

      find( first, last, x );

What search method does find use?



(a) Linear search
(b) Binary search
(c) It depends on the type of container.
(d) It depends on whether the data are sorted.

Correct answer is (a)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 90.00



Your performance was as follows:

1.
Access to ranges of elements in an STL container is typically handled by

(a) pointers
(b) suitable access member functions
(c) iterators
(d) references

Correct answer is (c)

Your score on this question is: 10.00

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



2.

Consider the following statement using the STL remove routine.

      remove( a, b, x );

What of the following accurately describes what the variables a and b represent?



(a) references
(b) iterators
(c) pointers
(d) containers

Correct answer is (b)

Your score on this question is: 10.00

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



3.

Consider the execution of the following.

      vector<int>  A(10,20);

Which of the following accurately describes what is created?



(a) An array of 10 arrays of ints, each of size 20
(b) An array of ints, indexed from 10 to 20
(c) An array of 10 ints, initializes to 20
(d) An array of 20 arrays of ints, each of size 10

Correct answer is (c)

Your score on this question is: 10.00

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



4.

Consider the execution of the following.

   list<int>  A(10);

Which of the following accurately describes what is created?



(a) 10 linked list of ints, all initially empty.
(b) A linked list of 10 ints, with each element initially containing random values.
(c) An empty linked list of ints, but reserves memory for 10 entries.
(d) A linked list of 10 ints, with each element initially 0.

Correct answer is (d)

Your score on this question is: 10.00

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



5.

Consider the following code fragment.

      stack<int>  S;
      S.push(123);
      S.push(456);

Now consider the following statement.

   cout << S.pop() << endl;

Which of the following most accurately describes what goes wrong when that statement is executed?



(a) pop() does not return a value.
(b) pop() requires an argument.
(c) An execution error occurs because an STL stack has no member function pop().
(d) An execution error occurs because pop() is a private member function.

Correct answer is (a)

Your score on this question is: 10.00

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



6.

For an STL iterator it and an STL container A, the expression

      it != A.end()

is used for which of the following purposes?



(a) To test whether the iterator points at some element of A
(b) To test whether the iterator is at the one-past-the-end position
(c) To reset the iterator to the beginning of A
(d) To test whether the iterator points to the last element of A

Correct answer is (b)

Your score on this question is: 10.00

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



7.

Consider the following code fragment.

      li    st<int>::const_iterator  it;
      for(  it = L.begin(); it != L.end(); ++it )
      *it = 0;

What is syntactically wrong with this fragment?



(a) Nothing
(b) The assignment using a const iterator
(c) The traversal using a const iterator
(d) The use of the prefix increment operator on a const iterator.

Correct answer is (b)

Your score on this question is: 10.00

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



8.

Consider the following code fragment.

      list<int>::iterator  it;
      for(  it = L.end(); it != L.begin(); --it )
      cout << *it << endl;

Which of the following most accurately describes what is wrong with it?



(a) Linked lists in the STL are circular, so the loop will never terminate.
(b) There is no decrement operation for list iterators.
(c) It will cause an attempt to access a non-existing list element.
(d) The operator* cannot be used on an STL iterator.

Correct answer is (c)

Your score on this question is: 10.00

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



9.
When using two iterators first and last to define a range of items in some container, which of the following is true concerning what they point to?

(a) It depends on the type of container.
(b) first points at the first item, and last at the last element.
(c) first points at the first item, and last at a position one past the last element.
(d) first points at a position one before the first item, and last at a position one past the last element.

Correct answer is (c)

Your score on this question is: 10.00

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



10.

The STL contains a general purpose search function:

      find( first, last, x );

What search method does find use?



(a) Linear search
(b) Binary search
(c) It depends on whether the data are sorted.
(d) It depends on the type of container.

Correct answer is (a)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.

Execution of the code fragment

    list<int>  A(10);

does which of the following?



(a) Creates an empty linked list of ints, but reserves memory for 10 entries
(b) Creates a linked list of 10 ints, with each element initially containing random values.
(c) Creates 10 linked list of ints, all initially empty.
(d) Creates a linked list of 10 ints, with each element initially 0.

Correct answer is (d)

Your score on this question is: 10.00

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



2.

Consider the execution of the following.

    list<int>  A(10,20);

Which of the following accurately describes what is created?



(a) An array of size 20 of linked list, each containing 20 ints
(b) a linked list of 10 linked lists, each containing 20 ints
(c) A linked list of 10 ints, with each element initially 20
(d) A linked list of size 10, each containing 10 arrays of ints of size 20

Correct answer is (c)

Your score on this question is: 10.00

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



3.

Execution of the code fragment

    stack<int,vector<int> >  S;

does which of the following?



(a) Creates a stack of integer vectors
(b) Creates a stack of ints, based on an integer vector
(c) Produces an execution error
(d) Creates a vector of integer stacks

Correct answer is (b)

Your score on this question is: 10.00

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



4.

Execution of the code fragment

    stack<int,list<int> >  S;

does which of the following?



(a) Creates a stack of integer lists
(b) Creates a list of integer stacks
(c) Produces an execution error
(d) Creates a stack of ints, based on an integer list

Correct answer is (d)

Your score on this question is: 10.00

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



5.

Suppose that both A and B are STL containers holding integers. Consider execution of the following code fragment.

 ostream_iterator  it( cout, " " );
 set_intersection( A.begin(), A.end(), B.begin(), B.end(), it );

Which of the following most accurately describes the results.



(a) Determines which integers are common to both containers, prints them out, and changes container B only so that, upon completion, A only holds the common elements.
(b) Determines which integers are common to both containers, and prints them out without changing the contents of the containers.
(c) Determines which integers are common to both containers, prints them out, and changes both containers so that, upon completion, the containers only hold the common elements.
(d) Determines which integers are common to both containers, prints them out, and changes container A only so that, upon completion, A only holds the common elements.

Correct answer is (b)

Your score on this question is: 10.00

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



6.

For an STL iterator it, execution of the statement

    it--;

does which of the following?



(a) Decreases by 1 the size of the container pointed to by it.
(b) Steps the iterator backwards to the previous item.
(c) Post-decrements the item to which the iterator points.
(d) Pre-decrements the item to which the iterator points.

Correct answer is (b)

Your score on this question is: 10.00

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



7.

For an STL iterator it and an STL container A, the expression

      it != A.end()

is used for which of the following purposes?



(a) To test whether the iterator points at some element of A
(b) To test whether the iterator is at the one-past-the-end position
(c) To reset the iterator to the beginning of A
(d) To test whether the iterator points to the last element of A

Correct answer is (b)

Your score on this question is: 10.00

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



8.

Consider the following code fragment.

      li    st<int>::const_iterator  it;
      for(  it = L.begin(); it != L.end(); ++it )
      *it = 0;

What is syntactically wrong with this fragment?



(a) Nothing
(b) The assignment using a const iterator
(c) The use of the prefix increment operator on a const iterator.
(d) The traversal using a const iterator

Correct answer is (b)

Your score on this question is: 10.00

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



9.
When using two iterators first and last to define a range of items in some container, which of the following is true concerning what they point to?

(a) first points at a position one before the first item, and last at a position one past the last element.
(b) first points at the first item, and last at the last element.
(c) first points at the first item, and last at a position one past the last element.
(d) It depends on the type of container.

Correct answer is (c)

Your score on this question is: 10.00

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



10.

The STL contains a general purpose search function:

      find( first, last, x );

What search method does find use?



(a) It depends on the type of container.
(b) It depends on whether the data are sorted.
(c) Linear search
(d) Binary search

Correct answer is (c)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.
Access to ranges of elements in an STL container is typically handled by

(a) references
(b) iterators
(c) suitable access member functions
(d) pointers

Correct answer is (b)

Your score on this question is: 10.00

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



2.

Consider the following statement using the STL remove routine.

      remove( a, b, x );

What of the following accurately describes what the variables a and b represent?



(a) pointers
(b) iterators
(c) containers
(d) references

Correct answer is (b)

Your score on this question is: 10.00

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



3.

Execution of the code fragment

    list<int>  A(10);

does which of the following?



(a) Creates a linked list of 10 ints, with each element initially containing random values.
(b) Creates 10 linked list of ints, all initially empty.
(c) Creates a linked list of 10 ints, with each element initially 0.
(d) Creates an empty linked list of ints, but reserves memory for 10 entries

Correct answer is (c)

Your score on this question is: 10.00

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



4.

Consider the execution of the following.

    list<int>  A(10,20);

Which of the following accurately describes what is created?



(a) A linked list of size 10, each containing 10 arrays of ints of size 20
(b) A linked list of 10 ints, with each element initially 20
(c) a linked list of 10 linked lists, each containing 20 ints
(d) An array of size 20 of linked list, each containing 20 ints

Correct answer is (b)

Your score on this question is: 10.00

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



5.

Consider the following code fragment.

      stack<int>  S;
      S.push(123);
      S.push(456);

Now consider the following statement.

   cout << S.pop() << endl;

Which of the following most accurately describes what goes wrong when that statement is executed?



(a) An execution error occurs because an STL stack has no member function pop().
(b) pop() does not return a value.
(c) An execution error occurs because pop() is a private member function.
(d) pop() requires an argument.

Correct answer is (b)

Your score on this question is: 10.00

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



6.

For an STL iterator it, execution of the statement

    ++it;

does which of the following?



(a) Post-increments the item to which the iterator points.
(b) Pre-increments the item to which the iterator points.
(c)

Increase by 1 the size of the container pointed to by it.


(d) Advances the iterator to the next item.

Correct answer is (d)

Your score on this question is: 10.00

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



7.

For an STL iterator it and an STL container A, the expression

      it != A.end()

is used for which of the following purposes?



(a) To reset the iterator to the beginning of A
(b) To test whether the iterator is at the one-past-the-end position
(c) To test whether the iterator points to the last element of A
(d) To test whether the iterator points at some element of A

Correct answer is (b)

Your score on this question is: 10.00

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



8.

Consider the following code fragment.

      li    st<int>::const_iterator  it;
      for(  it = L.begin(); it != L.end(); ++it )
      *it = 0;

What is syntactically wrong with this fragment?



(a) The use of the prefix increment operator on a const iterator.
(b) The traversal using a const iterator
(c) Nothing
(d) The assignment using a const iterator

Correct answer is (d)

Your score on this question is: 10.00

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



9.
When using two iterators first and last to define a range of items in some container, which of the following is true concerning what they point to?

(a) first points at the first item, and last at the last element.
(b) It depends on the type of container.
(c) first points at a position one before the first item, and last at a position one past the last element.
(d) first points at the first item, and last at a position one past the last element.

Correct answer is (d)

Your score on this question is: 10.00

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



10.

Consider the following statement using the STL sort() routine.

      sort( A.begin(), A.end(), f );

Which of the following most accurately describes the result of executing this statement?



(a) Container A is sorted using sorting algorithm f.
(b) Container A is sorted using the function f for assignments.
(c) Container A is sorted by applying function f to its elements.
(d) Container A is sorted using the Boolean valued function f for comparisons.

Correct answer is (d)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.

If A is an STL vector, then the effect of executing the statement

    A.push_back( x );

is to



(a) append x to A, without checking the size and capacity of A
(b) append x to A if there is room, and otherwise overwrites the currently last element of A
(c) append x to A if and only if the size of A is less than capacity of A
(d) check whether the capacity of A is larger than the size of A, enlarges A if necessary, and append x to A

Correct answer is (d)

Your score on this question is: 10.00

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



2.

Consider the following program segment.

vector<int>  A(10);
A.resize(0);
A.push_back(5000);

At the end of an execution of this fragment, the size of vector A is



(a) 10
(b) 1
(c) 5000
(d) 0

Correct answer is (b)

Your score on this question is: 10.00

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



3.

Consider the following code fragment, where L is a linked list of integers.

      for( it = L.begin(); it != L.end(); ++it )
        *it += 10;

Execution of this fragment has the effect of



(a) appending 10 to the list
(b) adding 10 to each list element
(c) stepping through the lists in increments of 10
(d) inserting a new element 10 after each list element

Correct answer is (b)

Your score on this question is: 10.00

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



4.

What, if anything, is wrong with the statement

      sort( L.begin(), L.end() );

where L is a linked list?



(a) Nothing
(b) It does not compile.
(c) Compiles and executes, is about as fast as L.sort(), but uses much more memory.
(d) Compiles and executes, but is much slower than L.sort().

Correct answer is (b)

Your score on this question is: 0.00

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



5.
Each of the following indicates a reasonable way to implement graphs EXCEPT

(a) a binary search tree
(b) an adjacency list structure
(c) a Boolean matrix
(d) an edge list

Correct answer is (a)

Your score on this question is: 10.00

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



6.
For an adjacency list implementation of a graph with n vertices and e edges, what is the order of the time required to calculate all the indegrees?

(a) O(n^3)
(b) O(n^2)
(c) O(n * e)
(d) O(n + e)

Correct answer is (d)

Your score on this question is: 10.00

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



7.
The time to convert an adjacency list implementation of a graph with n vertices and e edges to an adjacency matrix implementation has what order?

(a) O(n log n)
(b) O(n^2)
(c) O(n + e)
(d) O(n * e)

Correct answer is (b)

Your score on this question is: 0.00

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



8.
The time to convert an edge list implementation of a graph with n vertices and e edges to an adjacency matrix implementation has what order?

(a) O(n + e)
(b) O(n^2)
(c) O(n * e)
(d) O(n log n)

Correct answer is (b)

Your score on this question is: 0.00

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



9.
If A is an adjacency matrix for a graph G, then the matrix product A * A represents all pairs of vertices (u,v) such that

(a) there is a vertex x such that (u,x) and (v,x) are edges of G
(b) there is a vertex x such that (u,x) and (x,v) are edges of G
(c) u and v are not connected by an edge
(d) u and v are connected by two edges

Correct answer is (b)

Your score on this question is: 10.00

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



10.
The time to compute the reverse graph for an adjacency list implementation of a graph with n vertices and e edges has what order? (The reverse graph has the same vertices but all the edges are reversed.)

(a) O(n * e)
(b) O(n)
(c) O(n + e)
(d) O(n^2)

Correct answer is (c)

Your score on this question is: 0.00

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



Go to top of assessment.

Total score: 60.00



Your performance was as follows:

1.
The capacity of an STL vector is defined to be the

(a) difference between the current number of elements and the maximum number of elements
(b) maximum number of elements that can be stored in the vector without resizing
(c) number of elements currently stored in the vector
(d) maximum number of elements the vector could possibly have on the given machine

Correct answer is (b)

Your score on this question is: 10.00

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



2.

If A is an STL vector, then the effect of executing the statement

      A[i] = x;

is to



(a) check array bounds, enlarge the vector if necessary, and then write x to position i
(b) write x to position i of the vector, without bounds checking
(c) create an iterator x pointing to position i in the array
(d) check array bounds, and write x to position i if and only if i is in the proper range

Correct answer is (b)

Your score on this question is: 10.00

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



3.

Consider the following code fragment concerning the STL list class.

      list<int>   L(10);
      L[3] = 555;

The fragment will produce a compile time error because



(a) the class list does not support a constructor with given length
(b) the class list does not support the bracket operator
(c) the class list only supports the const version of the bracket operator
(d) L is an array of 10 list objects, and we cannot assign 555 to a list object

Correct answer is (b)

Your score on this question is: 10.00

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



4.

What, if anything, is wrong with the statement

      sort( L.begin(), L.end() );

where L is a linked list?



(a) Compiles and executes, but is much slower than L.sort().
(b) Nothing
(c) Compiles and executes, is about as fast as L.sort(), but uses much more memory.
(d) It does not compile.

Correct answer is (d)

Your score on this question is: 10.00

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



5.

Assume that L is an STL list object. Consider the following statement.

      while( L.size() > 0 ) { ... }

Which of the following most accurately describes what is wrong with that statement?



(a) The size() function takes time linear in the length of the list, so this is potentially very inefficient.
(b) The loop never terminates since size() always returns a positive value.
(c) Does not compile, since size() is not a member function of class list.
(d) size() requires an argument.

Correct answer is (a)

Your score on this question is: 0.00

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



6.
For an adjacency list implementation of a graph with n vertices and e edges, what is the order of the time required to calculate all the outdegrees?

(a) O(n^3)
(b) O(n + e)
(c) O(n * e)
(d) O(n^2)

Correct answer is (b)

Your score on this question is: 0.00

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



7.
The time to convert an adjacency list implementation of a graph with n vertices and e edges to an adjacency matrix implementation has what order?

(a) O(n^2)
(b) O(n log n)
(c) O(n + e)
(d) O(n * e)

Correct answer is (a)

Your score on this question is: 10.00

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



8.
The definition of the product of two Boolean matrices is the same as the usual product of matrices except that

(a) addition is interpreted as logical-or, and multiplication is interpreted as logical-and
(b) addition is interpreted as logical-and, and multiplication is interpreted as logical-or
(c) false is interpreted as 0, true is interpreted as 1, and then ordinary matrix multiplication is used
(d) addition is interpreted as logical-and, and multiplication is interpreted as logical-xor

Correct answer is (a)

Your score on this question is: 0.00

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



9.
The time to compute the reverse graph for an adjacency matrix implementation of a graph with n vertices and e edges has what order? (The reverse graph has the same vertices but all the edges are reversed.)

(a) O(n^2)
(b) O(n)
(c) O(n + e)
(d) O(n * e)

Correct answer is (a)

Your score on this question is: 0.00

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



10.
The time to perform depth first search, starting at the first vertex of a graph with n vertices and e edges implemented as an adjacency list has what order?

(a) O(n * e)
(b) O(n + e)
(c) O(n)
(d) O(n^2)

Correct answer is (b)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 60.00



Your performance was as follows:

1.

Consider the following program fragment.

      vector<int>   A(10);
      A.push_back( 5000 );

At the end of an execution of this fragment, the size of vector A is



(a) 10
(b) 5000
(c) dependent on machine and compiler
(d) larger than 10

Correct answer is (d)

Your score on this question is: 0.00

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



2.

Consider the following code fragment, where L is a linked list of integers.

      for( it = L.begin(); it != L.end(); ++it )
        *it += 10;

Execution of this fragment has the effect of



(a) stepping through the lists in increments of 10
(b) appending 10 to the list
(c) adding 10 to each list element
(d) inserting a new element 10 after each list element

Correct answer is (c)

Your score on this question is: 10.00

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



3.

Consider the following code fragment.

      Rotate( list<int>& L, int r )
      {
          for( int i = 0; i < r; i++ )
          {
              L.push_back( L.front() );
              L.pop_front();
          }
      }

What, if anything, is wrong with using this fragment to rotate a list L?



(a) It should be written as: L.push_back( L.pop_front() );
(b) Nothing
(c) It does not rotate the list, it reverses it.
(d) It is inefficient because of all the copying, allocation, and deallocation.

Correct answer is (d)

Your score on this question is: 0.00

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



4.

Assume that L is an STL list object. Consider the following statement.

      while( L.size() > 0 ) { ... }

Which of the following most accurately describes what is wrong with that statement?



(a) Does not compile, since size() is not a member function of class list.
(b) size() requires an argument.
(c) The loop never terminates since size() always returns a positive value.
(d) The size() function takes time linear in the length of the list, so this is potentially very inefficient.

Correct answer is (d)

Your score on this question is: 10.00

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



5.
Of the following code outlines, which provides the best way to obtain a stack class from an already existing linked list class?

(a) template<class T> class Stack: { list<T> L; ... };
(b) template<class T> class Stack: private list<T> { ... };
(c) template<class T> class Stack: public list<T> { ... };
(d) template<class T> class Stack: { list<T> &L; ... };

Correct answer is (b)

Your score on this question is: 10.00

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



6.
Each of the following indicates a reasonable way to implement graphs EXCEPT

(a) a Boolean matrix
(b) a binary search tree
(c) an edge list
(d) an adjacency list structure

Correct answer is (b)

Your score on this question is: 10.00

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



7.
For an adjacency matrix implementation of a directed graph with n vertices and e edges, what is the order of the time required to calculate all the outdegrees?

(a) O(n^3)
(b) O(n + e)
(c) O(n * e)
(d) O(n^2)

Correct answer is (d)

Your score on this question is: 0.00

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



8.
The time to convert an adjacency list implementation of a graph with n vertices and e edges to an adjacency matrix implementation has what order?

(a) O(n * e)
(b) O(n + e)
(c) O(n^2)
(d) O(n log n)

Correct answer is (c)

Your score on this question is: 10.00

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



9.
The time to compute the reverse graph for an adjacency list implementation of a graph with n vertices and e edges has what order? (The reverse graph has the same vertices but all the edges are reversed.)

(a) O(n^2)
(b) O(n * e)
(c) O(n + e)
(d) O(n)

Correct answer is (c)

Your score on this question is: 0.00

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



10.
The time to perform breadth first search, starting at the first vertex of a graph with n vertices and e edges implemented as an adjacency list has what order?

(a) O(n)
(b) O(n^2)
(c) O(n + e)
(d) O(n * e)

Correct answer is (c)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 60.00



Your performance was as follows:

1.

If A is an STL vector, then the effect of executing the statement

      A[i] = x;

is to



(a) write x to position i of the vector, without bounds checking
(b) check array bounds, enlarge the vector if necessary, and then write x to position i
(c) check array bounds, and write x to position i if and only if i is in the proper range
(d) create an iterator x pointing to position i in the array

Correct answer is (a)

Your score on this question is: 10.00

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



2.

Consider the following program fragment.

      vector<int>   A(10);
      A.push_back( 5000 );

At the end of an execution of this fragment, the size of vector A is



(a) 10
(b) 5000
(c) dependent on machine and compiler
(d) larger than 10

Correct answer is (d)

Your score on this question is: 0.00

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



3.

Consider the following two ways of creating a vector filled with 1,2,...,1000.

   // method I
       vector<int>   A(1000);              
       iota( A.begin(), A.end(), 1 );
      // method II
    vector<int>   A; 
    for( int i = 1; i <= 1000; i++ )
          A.push_back( i );

Which of the following is true about these two methods?



(a) Method I is slightly faster than II.
(b) Method I is very much faster than II.
(c) Which method is faster depends on machine and compiler.
(d) Method II is slightly faster than I.

Correct answer is (a)

Your score on this question is: 0.00

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



4.

Consider the following code fragment concerning the STL list class.

      list<int>   L(10);
      L[3] = 555;

The fragment will produce a compile time error because



(a) the class list only supports the const version of the bracket operator
(b) the class list does not support the bracket operator
(c) the class list does not support a constructor with given length
(d) L is an array of 10 list objects, and we cannot assign 555 to a list object

Correct answer is (b)

Your score on this question is: 10.00

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



5.

Consider the following code fragment.

      Rotate( list<int>& L, int r )
      {
          for( int i = 0; i < r; i++ )
          {
              L.push_back( L.front() );
              L.pop_front();
          }
      }

What, if anything, is wrong with using this fragment to rotate a list L?



(a) It does not rotate the list, it reverses it.
(b) Nothing
(c) It is inefficient because of all the copying, allocation, and deallocation.
(d) It should be written as: L.push_back( L.pop_front() );

Correct answer is (c)

Your score on this question is: 10.00

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



6.
Each of the following indicates a reasonable way to implement graphs EXCEPT

(a) a binary search tree
(b) an edge list
(c) a Boolean matrix
(d) an adjacency list structure

Correct answer is (a)

Your score on this question is: 10.00

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



7.
For an adjacency list implementation of a graph with n vertices and e edges, what is the order of the time required to calculate all the outdegrees?

(a) O(n * e)
(b) O(n^2)
(c) O(n + e)
(d) O(n^3)

Correct answer is (c)

Your score on this question is: 10.00

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



8.
The time to convert an adjacency list implementation of a graph with n vertices and e edges to an adjacency matrix implementation has what order?

(a) O(n log n)
(b) O(n + e)
(c) O(n^2)
(d) O(n * e)

Correct answer is (c)

Your score on this question is: 10.00

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



9.
The time to compute the reverse graph for an adjacency matrix implementation of a graph with n vertices and e edges has what order? (The reverse graph has the same vertices but all the edges are reversed.)

(a) O(n * e)
(b) O(n + e)
(c) O(n)
(d) O(n^2)

Correct answer is (d)

Your score on this question is: 10.00

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



10.
The time to compute the reverse graph for an adjacency list implementation of a graph with n vertices and e edges has what order? (The reverse graph has the same vertices but all the edges are reversed.)

(a) O(n + e)
(b) O(n * e)
(c) O(n^2)
(d) O(n)

Correct answer is (a)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 80.00



Your performance was as follows:

1.
The capacity of an STL vector is defined to be the

(a) maximum number of elements that can be stored in the vector without resizing
(b) difference between the current number of elements and the maximum number of elements
(c) number of elements currently stored in the vector
(d) maximum number of elements the vector could possibly have on the given machine

Correct answer is (a)

Your score on this question is: 10.00

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



2.

If A is an STL vector, then the effect of executing the statement

    A.push_back( x );

is to



(a) append x to A if there is room, and otherwise overwrites the currently last element of A
(b) append x to A, without checking the size and capacity of A
(c) append x to A if and only if the size of A is less than capacity of A
(d) check whether the capacity of A is larger than the size of A, enlarges A if necessary, and append x to A

Correct answer is (d)

Your score on this question is: 10.00

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



3.

Consider the following program segment.

vector<int>  A(10);
A.resize(0);
A.push_back(5000);

At the end of an execution of this fragment, the size of vector A is



(a) 5000
(b) 1
(c) 10
(d) 0

Correct answer is (b)

Your score on this question is: 10.00

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



4.

Consider the following two ways of creating a vector filled with 1,2,...,1000.

   // method I
       vector<int>   A(1000);              
       iota( A.begin(), A.end(), 1 );
      // method II
    vector<int>   A; 
    for( int i = 1; i <= 1000; i++ )
          A.push_back( i );

Which of the following is true about these two methods?



(a) Method I is slightly faster than II.
(b) Method I is very much faster than II.
(c) Method II is slightly faster than I.
(d) Which method is faster depends on machine and compiler.

Correct answer is (a)

Your score on this question is: 10.00

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



5.

Consider the following code fragment concerning the STL list class.

      list<int>   L(10);
      L[3] = 555;

The fragment will produce a compile time error because



(a) the class list does not support a constructor with given length
(b) the class list only supports the const version of the bracket operator
(c) the class list does not support the bracket operator
(d) L is an array of 10 list objects, and we cannot assign 555 to a list object

Correct answer is (c)

Your score on this question is: 10.00

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



6.

Consider the following code fragment, where L is a linked list of integers.

      for( it = L.begin(); it != L.end(); ++it )
        *it += 10;

Execution of this fragment has the effect of



(a) adding 10 to each list element
(b) appending 10 to the list
(c) inserting a new element 10 after each list element
(d) stepping through the lists in increments of 10

Correct answer is (a)

Your score on this question is: 10.00

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



7.

Assume that L is an STL list object. Consider the following statement.

      while( L.size() > 0 ) { ... }

Which of the following most accurately describes what is wrong with that statement?



(a) size() requires an argument.
(b) The size() function takes time linear in the length of the list, so this is potentially very inefficient.
(c) The loop never terminates since size() always returns a positive value.
(d) Does not compile, since size() is not a member function of class list.

Correct answer is (b)

Your score on this question is: 10.00

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



8.
The definition of the product of two Boolean matrices is the same as the usual product of matrices except that

(a) addition is interpreted as logical-and, and multiplication is interpreted as logical-or
(b) addition is interpreted as logical-and, and multiplication is interpreted as logical-xor
(c) false is interpreted as 0, true is interpreted as 1, and then ordinary matrix multiplication is used
(d) addition is interpreted as logical-or, and multiplication is interpreted as logical-and

Correct answer is (d)

Your score on this question is: 10.00

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



9.
If A is an adjacency matrix for a graph G, then the matrix product A * A represents all pairs of vertices (u,v) such that

(a) there is a vertex x such that (u,x) and (v,x) are edges of G
(b) there is a vertex x such that (u,x) and (x,v) are edges of G
(c) u and v are not connected by an edge
(d) u and v are connected by two edges

Correct answer is (b)

Your score on this question is: 10.00

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



10.
The time to compute the reverse graph for an adjacency list implementation of a graph with n vertices and e edges has what order? (The reverse graph has the same vertices but all the edges are reversed.)

(a) O(n * e)
(b) O(n + e)
(c) O(n)
(d) O(n^2)

Correct answer is (b)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.

Consider the following recursive definition of a function search that performs search in a binary tree.

bool search(Type  a, Tree  T)  {
  if (empty(T))  {
    return false;
  }
  else
  if(a == data(T))  {
    return true;
  }
  else  {
    bool  bl = search(a, left(L));
    bool  br = search(a, right(L));
    return  bl || br;
  }
}

Which of the following describes a problem with the function when executed?



(a) It might fail to terminate.
(b) It might terminate prematurely.
(c) It might take quadratic time unnecessarily.
(d) It might take linear time unnecessarily.

Correct answer is (d)

Your score on this question is: 10.00

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



2.
A node in a tree that does not have any children is called

(a) an empty node
(b) a leaf
(c) an internal node
(d) a root

Correct answer is (b)

Your score on this question is: 10.00

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



3.
Which of the following is true about the total number of nodes in a binary tree with depth 2?

(a) It is at most 4.
(b) There is no bound on the number of nodes.
(c) It is at most 7.
(d) It is at most 2.

Correct answer is (c)

Your score on this question is: 10.00

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



4.
A full node in a binary tree has how many children?

(a) 1
(b) 2
(c) 0
(d) 1 or 2

Correct answer is (b)

Your score on this question is: 10.00

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



5.
In the standard array implementation of a binary tree, the nodes are stored in an array. What is the convention for the array position of the left child of the node in position p of the array?

(a) 2 * p
(b) p + 1
(c) p/2
(d) 2 * p + 1

Correct answer is (a)

Your score on this question is: 10.00

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



6.

Consider the following pseudo-code, which indicates part of a standard binary tree algorithm.

      print( node )
      {
      print  data;
      if( there is a left child )  print( left child );
      if( there is a right child )  print( right child );
      }

Which of the following is the standard name for this algorithm?



(a) Preorder traversal
(b) Binary search
(c) Inorder traversal
(d) Postorder traversal

Correct answer is (a)

Your score on this question is: 10.00

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



7.
A tree can be implemented as a graph whose vertices are the nodes of the tree and where an edge (u,v) indicates that u is the parent of v. Which of the following indicates all the nodes of such an implementation that are reachable by a depth first search starting at the root?

(a) Only the nodes in the left subtree of the root
(b) Only the leaves of the tree
(c) All nodes in the tree
(d) Only the interior nodes of the tree

Correct answer is (c)

Your score on this question is: 10.00

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



8.
Which of the following traversals of a binary search tree will produce a sorted list if a visit to a node prints what is stored there?

(a) Preorder
(b) Postorder
(c) Level-by-level
(d) Inorder

Correct answer is (d)

Your score on this question is: 10.00

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



9.
During a failed search for an element in a completely balanced binary search tree of size 1,000,000, approximately how many nodes of the tree is visited?

(a) 200
(b) 1000
(c) 20
(d) 10,000

Correct answer is (c)

Your score on this question is: 0.00

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



10.
If numbers 1,2,...,n are inserted into a binary search tree in random order, then the result for large n is a

(a) completely balanced tree
(b) tree where all nodes are full
(c) totally unbalanced tree
(d) reasonably balanced tree

Correct answer is (d)

Your score on this question is: 0.00

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



Go to top of assessment.

Total score: 80.00



Your performance was as follows:

1.
Which of the following is true about the depth of a tree with exactly 3 nodes?

(a) There is no bound on the depth.
(b) It is at most 2.
(c) It is at most 3.
(d) It is at most 1.

Correct answer is (b)

Your score on this question is: 10.00

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



2.
Which of the following is true about the total number of nodes in a binary tree with depth 2?

(a) It is at most 2.
(b) There is no bound on the number of nodes.
(c) It is at most 4.
(d) It is at most 7.

Correct answer is (d)

Your score on this question is: 10.00

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



3.
A full node in a binary tree has how many children?

(a) 2
(b) 1
(c) 1 or 2
(d) 0

Correct answer is (a)

Your score on this question is: 10.00

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



4.
In the standard array implementation of a binary tree the nodes are stored in an array. What is the convention for the array position of the parent of the node in position p of the array?

(a) p/2
(b) 2 * p + 1
(c) 2 * p
(d) p - 1

Correct answer is (a)

Your score on this question is: 10.00

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



5.

Consider the following pseudo-code, which indicates part of a standard binary tree algorithm.

      print( node )
      {
      if( there is a left child )  print( left child );
      print  data;
      if( there is a right child )  print( right child );
      }

Which of the following is the standard name for this algorithm?



(a) Binary search
(b) Inorder traversal
(c) Postorder traversal
(d) Preorder traversal

Correct answer is (b)

Your score on this question is: 10.00

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



6.
A tree can be implemented as a graph whose vertices are the nodes of the tree and where an edge (u,v) indicates that u is the parent of v. Which of the following indicates all the nodes of such an implementation that are reachable by a depth first search starting at the root?

(a) Only the nodes in the left subtree of the root
(b) Only the leaves of the tree
(c) All nodes in the tree
(d) Only the interior nodes of the tree

Correct answer is (c)

Your score on this question is: 10.00

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



7.
Which of the following traversals of a binary search tree will produce a sorted list if a visit to a node prints what is stored there?

(a) Preorder
(b) Inorder
(c) Level-by-level
(d) Postorder

Correct answer is (b)

Your score on this question is: 10.00

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



8.
Searching for an element in a binary search tree takes O(s) steps where s is

(a) the depth of the tree
(b) the number of leaves of the tree
(c) 1 (the search takes constant time)
(d) the size of the tree

Correct answer is (a)

Your score on this question is: 10.00

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



9.

Suppose S is a binary search tree and x is not an element of S. Consider the following code fragment.

      S.remove( x );
      S.insert( x );

If T is the tree that results from executing the fragment, what is the relationship between S and T?



(a) S and T differ but how depends on S.
(b) S is a proper subtree of T.
(c) S and T differ in exactly the root.
(d) S and T are the same.

Correct answer is (a)

Your score on this question is: 0.00

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



10.
If numbers 1,2,...,n are inserted into a binary search tree, in order, then the result for large n is a

(a) totally unbalanced tree
(b) mildly unbalanced tree
(c) completely balanced tree
(d) tree where all nodes are full

Correct answer is (a)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 90.00



Your performance was as follows:

1.

Consider the following recursive definition of a function search that performs search in a binary tree.

bool search(Type  a, Tree  T)  {
  if (empty(T))  {
    return false;
  }
  else
  if(a == data(T))  {
    return true;
  }
  else  {
    bool  bl = search(a, left(L));
    bool  br = search(a, right(L));
    return  bl || br;
  }
}

Which of the following describes a problem with the function when executed?



(a) It might take linear time unnecessarily.
(b) It might terminate prematurely.
(c) It might fail to terminate.
(d) It might take quadratic time unnecessarily.

Correct answer is (a)

Your score on this question is: 10.00

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



2.
A node in a tree that does not have a predecessor is called

(a) an internal node
(b) a root
(c) a parent node
(d) a leaf

Correct answer is (b)

Your score on this question is: 0.00

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



3.
A node in a tree that does not have any children is called

(a) a leaf
(b) an internal node
(c) an empty node
(d) a root

Correct answer is (a)

Your score on this question is: 10.00

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



4.
Which of the following is true about the total number of nodes in a tree with depth 2?

(a) It is at most 3.
(b) It is at most 1.
(c) There is no bound on the number of nodes.
(d) It is at most 2.

Correct answer is (c)

Your score on this question is: 0.00

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



5.

Consider the following pseudo-code, which indicates part of a standard binary tree algorithm.

      print( node )
      {
      print  data;
      if( there is a left child )  print( left child );
      if( there is a right child )  print( right child );
      }

Which of the following is the standard name for this algorithm?



(a) Inorder traversal
(b) Postorder traversal
(c) Preorder traversal
(d) Binary search

Correct answer is (c)

Your score on this question is: 10.00

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



6.

Consider the following pseudo-code, which indicates part of a standard binary tree algorithm.

      print( node )
      {
      if( there is a left child )  print( left child );
      print  data;
      if( there is a right child )  print( right child );
      }

Which of the following is the standard name for this algorithm?



(a) Inorder traversal
(b) Preorder traversal
(c) Postorder traversal
(d) Binary search

Correct answer is (a)

Your score on this question is: 10.00

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



7.
Which of the following traversals of a binary search tree will produce a sorted list if a visit to a node prints what is stored there?

(a) Inorder
(b) Preorder
(c) Postorder
(d) Level-by-level

Correct answer is (a)

Your score on this question is: 10.00

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



8.
During a failed search for an element in a completely balanced binary search tree of size 1,000,000, approximately how many nodes of the tree is visited?

(a) 1000
(b) 10,000
(c) 200
(d) 20

Correct answer is (d)

Your score on this question is: 10.00

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



9.
If numbers 1,2,...,n are inserted into a binary search tree, in order, then the result for large n is a

(a) mildly unbalanced tree
(b) tree where all nodes are full
(c) completely balanced tree
(d) totally unbalanced tree

Correct answer is (d)

Your score on this question is: 10.00

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



10.
If numbers 1,2,...,n are inserted into a binary search tree in random order, then the result for large n is a

(a) reasonably balanced tree
(b) tree where all nodes are full
(c) totally unbalanced tree
(d) completely balanced tree

Correct answer is (a)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 80.00



Your performance was as follows:

1.

Consider the following recursive definition of a function search that performs search in a binary tree.

bool search(Type  a, Tree  T)  {
  if (empty(T))  {
    return false;
  }
  else
  if(a == data(T))  {
    return true;
  }
  else  {
    bool  bl = search(a, left(L));
    bool  br = search(a, right(L));
    return  bl || br;
  }
}

Which of the following describes a problem with the function when executed?



(a) It might take linear time unnecessarily.
(b) It might fail to terminate.
(c) It might take quadratic time unnecessarily.
(d) It might terminate prematurely.

Correct answer is (a)

Your score on this question is: 10.00

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



2.
A node in a tree that does not have a predecessor is called

(a) an internal node
(b) a leaf
(c) a root
(d) a parent node

Correct answer is (c)

Your score on this question is: 10.00

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



3.
Which of the following is true about the depth of a tree with exactly 3 nodes?

(a) There is no bound on the depth.
(b) It is at most 1.
(c) It is at most 2.
(d) It is at most 3.

Correct answer is (c)

Your score on this question is: 10.00

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



4.
Which of the following is true about the total number of nodes in a binary tree with depth 2?

(a) It is at most 2.
(b) There is no bound on the number of nodes.
(c) It is at most 4.
(d) It is at most 7.

Correct answer is (d)

Your score on this question is: 10.00

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



5.
A full node in a binary tree has how many children?

(a) 1
(b) 2
(c) 0
(d) 1 or 2

Correct answer is (b)

Your score on this question is: 10.00

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



6.

Consider the following pseudo-code, which indicates part of a standard binary tree algorithm.

      print( node )
      {
      print  data;
      if( there is a left child )  print( left child );
      if( there is a right child )  print( right child );
      }

Which of the following is the standard name for this algorithm?



(a) Inorder traversal
(b) Binary search
(c) Postorder traversal
(d) Preorder traversal

Correct answer is (d)

Your score on this question is: 10.00

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



7.
Which of the following traversals of a binary search tree will produce a sorted list if a visit to a node prints what is stored there?

(a) Level-by-level
(b) Postorder
(c) Inorder
(d) Preorder

Correct answer is (c)

Your score on this question is: 10.00

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



8.

Suppose S is a binary search tree and x is not an element of S. Consider the following code fragment.

      S.remove( x );
      S.insert( x );

If T is the tree that results from executing the fragment, what is the relationship between S and T?



(a) S and T differ but how depends on S.
(b) S is a proper subtree of T.
(c) S and T differ in exactly the root.
(d) S and T are the same.

Correct answer is (a)

Your score on this question is: 10.00

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



9.
If numbers 1,2,...,n are inserted into a binary search tree, in order, then the result for large n is a

(a) totally unbalanced tree
(b) tree where all nodes are full
(c) completely balanced tree
(d) mildly unbalanced tree

Correct answer is (a)

Your score on this question is: 10.00

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



10.
Which of the following sequences cannot represent values visited during a binary search?

(a) 50, 40, 30, 20, 10
(b) 30, 50, 40, 45, 42
(c) 10, 20, 30, 40, 50
(d) 10, 20, 30, 15, 18

Correct answer is (d)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.
A node in a tree that does not have a predecessor is called

(a) an internal node
(b) a root
(c) a leaf
(d) a parent node

Correct answer is (b)

Your score on this question is: 10.00

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



2.
A node in a tree that does not have any children is called

(a) an empty node
(b) a leaf
(c) an internal node
(d) a root

Correct answer is (b)

Your score on this question is: 10.00

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



3.
Which of the following is true about the total number of nodes in a tree with depth 2?

(a) There is no bound on the number of nodes.
(b) It is at most 2.
(c) It is at most 1.
(d) It is at most 3.

Correct answer is (a)

Your score on this question is: 10.00

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



4.
A full node in a binary tree has how many children?

(a) 0
(b) 1 or 2
(c) 1
(d) 2

Correct answer is (d)

Your score on this question is: 10.00

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



5.
In the standard array implementation of a binary tree the nodes are stored in an array. What is the convention for the array position of the parent of the node in position p of the array?

(a) p - 1
(b) p/2
(c) 2 * p
(d) 2 * p + 1

Correct answer is (b)

Your score on this question is: 10.00

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



6.
In the standard array implementation of a binary tree, the nodes are stored in an array. What is the convention for the array position of the left child of the node in position p of the array?

(a) 2 * p + 1
(b) p + 1
(c) p/2
(d) 2 * p

Correct answer is (d)

Your score on this question is: 10.00

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



7.

Consider the following pseudo-code, which indicates part of a standard binary tree algorithm.

      print( node )
      {
      print  data;
      if( there is a left child )  print( left child );
      if( there is a right child )  print( right child );
      }

Which of the following is the standard name for this algorithm?



(a) Preorder traversal
(b) Binary search
(c) Inorder traversal
(d) Postorder traversal

Correct answer is (a)

Your score on this question is: 10.00

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



8.
A tree can be implemented as a graph whose vertices are the nodes of the tree and where an edge (u,v) indicates that u is the parent of v. Which of the following indicates all the nodes of such an implementation that are reachable by a depth first search starting at the root?

(a) Only the leaves of the tree
(b) Only the nodes in the left subtree of the root
(c) Only the interior nodes of the tree
(d) All nodes in the tree

Correct answer is (d)

Your score on this question is: 10.00

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



9.
During a failed search for an element in a completely balanced binary search tree of size 1,000,000, approximately how many nodes of the tree is visited?

(a) 1000
(b) 20
(c) 10,000
(d) 200

Correct answer is (b)

Your score on this question is: 10.00

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



10.
If numbers 1,2,...,n are inserted into a binary search tree in random order, then the result for large n is a

(a) tree where all nodes are full
(b) reasonably balanced tree
(c) completely balanced tree
(d) totally unbalanced tree

Correct answer is (b)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.
In the context of hashing, what is meant by a collision?

(a) The insertion algorithm cannot find an empty slot in the table.
(b) Two key/value pairs have the same value.
(c) Two different keys hash to the same slot.
(d) The hash function returns a value larger than the table size.

Correct answer is (c)

Your score on this question is: 10.00

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



2.
If a hash table of size m contains n items, what is the load factor of the table?

(a) m - n
(b) m/n
(c) n/m
(d) n + m

Correct answer is (c)

Your score on this question is: 10.00

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



3.
Which of the following is true about a good hash function?

(a) It should produce small outputs for small inputs.
(b) It should produce apparently random values for given items.
(c) It should never output a prime number.
(d) It should only output prime numbers.

Correct answer is (b)

Your score on this question is: 10.00

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



4.
Which of the following indicates the reaction time, in general, for searching in a chaining hash table of size 1,000,000 with a load factor of 0.9?

(a) It may fail to find an element that is present.
(b) It may "find" an element that is no longer there.
(c) It will be noticeably slow.
(d) It will be almost instantaneous.

Correct answer is (d)

Your score on this question is: 0.00

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



5.
In searching for an entry with key k in an open addressing hash table, the slot p = hash(k) is computed, after which it is necessary to

(a) check only if the entry in slot p has key k
(b) traverse a linked list to check if any entry there has key k
(c) compute p + k to find the right position for the entry
(d) check if the entry in slot p has key k, then p+1 if necessary, then p+2, and so forth.

Correct answer is (d)

Your score on this question is: 10.00

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



6.

Consider the following outline of a memoized function.

      int  f( int x ) { ... }

How many steps does it take to make 10000 calls to f on input x = 1000?



(a) About 10000 steps, plus computing f(1000)
(b) About 10000 steps
(c) About 10000 times the number of steps used in computing f(1000)
(d) A small, constant number of steps

Correct answer is (a)

Your score on this question is: 0.00

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



7.
What order should be expected when the occupied slots in an open addressing hash table with load factor 0.9 are printed in the order in which they appear in the table?

(a) Random order
(b) Ascending order
(c) Descending order
(d) Blocks of items in ascending order

Correct answer is (a)

Your score on this question is: 10.00

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



8.
In order for the division method to work in the context of hashing, the table size should be

(a) a prime
(b) a perfect square
(c) anything but a prime
(d) a power of two

Correct answer is (a)

Your score on this question is: 10.00

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



9.
Which of the following correctly indicates where keys and associated values are stored in hash tables when chaining is used?

(a) Each key is stored in the table, and the associated value is stored in a linked list.
(b) The keys are stored in the table, and the associated values are stored in the list header.
(c) Each key/value pair is stored in a node of a linked list.
(d) The keys are stored in the list header, and the associated values are stored in the linked lists.

Correct answer is (c)

Your score on this question is: 0.00

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



10.

Consider the following definition of a function hash.

      size_t  hash( const char *str )
      {
          size_t  h = 0;
          for( ; *str != '0'; str++ )
               h += *str;
      }

What, if anything, is wrong with hash as a hash function for null-terminated strings?



(a) If the string is very long, there will be overflow.
(b) All permutations of a word hash to the same slot.
(c) It makes no sense to add characters.
(d) Nothing

Correct answer is (b)

Your score on this question is: 0.00

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



Go to top of assessment.

Total score: 60.00



Your performance was as follows:

1.
Suppose hash() is a hash function. The main idea behind hashing is to use a key k to store a value v in which position of a table?

(a) hash(v)
(b) hash(k,v)
(c) hash() (a random position computed by the hash function using k)
(d) hash(k)

Correct answer is (d)

Your score on this question is: 0.00

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



2.
In the context of hashing, what is meant by a collision?

(a) Two different keys hash to the same slot.
(b) The hash function returns a value larger than the table size.
(c) Two key/value pairs have the same value.
(d) The insertion algorithm cannot find an empty slot in the table.

Correct answer is (a)

Your score on this question is: 10.00

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



3.
If a hash table of size m contains n items, what is the load factor of the table?

(a) n/m
(b) m - n
(c) m/n
(d) n + m

Correct answer is (a)

Your score on this question is: 10.00

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



4.
Which of the following is true about a good hash function?

(a) It should never output a prime number.
(b) It should produce apparently random values for given items.
(c) It should produce small outputs for small inputs.
(d) It should only output prime numbers.

Correct answer is (b)

Your score on this question is: 10.00

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



5.
Which of the following indicates the reaction time, in general, for searching in an open addressing hash table of size 1,000,000 with a load factor of 0.9?

(a) It may fail to find an element that is present.
(b) It will be noticeably slow.
(c) It may "find" an element that is no longer there.
(d) It will be almost instantaneous.

Correct answer is (b)

Your score on this question is: 10.00

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



6.
Which of the following indicates the reaction time, in general, for searching in a chaining hash table of size 1,000,000 with a load factor of 0.9?

(a) It may "find" an element that is no longer there.
(b) It will be noticeably slow.
(c) It may fail to find an element that is present.
(d) It will be almost instantaneous.

Correct answer is (d)

Your score on this question is: 10.00

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



7.
In searching for an entry with key k in an open addressing hash table, the slot p = hash(k) is computed, after which it is necessary to

(a) traverse a linked list to check if any entry there has key k
(b) check only if the entry in slot p has key k
(c) compute p + k to find the right position for the entry
(d) check if the entry in slot p has key k, then p+1 if necessary, then p+2, and so forth.

Correct answer is (d)

Your score on this question is: 10.00

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



8.
Which of the following correctly indicates where keys and associated values are stored in hash tables when open addressing is used?

(a) Each key is stored in a slot in the table, and the associated value is stored in one of the slots that follow.
(b) The keys are stored in the list header, and the associated values are stored in linked lists.
(c) The values are stored in a slot in the table, and keys are stored in the slots that follow.
(d) Each key/value pair is stored in the table.

Correct answer is (d)

Your score on this question is: 10.00

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



9.
The appropriate return type for a search function on a chaining hash table is

(a) a Boolean
(b) an iterator
(c) a list node
(d) a pair consisting of a Boolean and an iterator

Correct answer is (d)

Your score on this question is: 10.00

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



10.

Consider the following definition of a function hash.

   size_t  hash( const char *str )
      {
          size_t  h = 0;
          for( ; *str != '0'; str++ )
               h = h*256 + *str;
      }

What, if anything, is wrong with hash as a hash function for null-terminated strings?



(a) It is very slow to compute.
(b) It only takes into account the last few characters long strings.
(c) If the string is very long, there will be overflow.
(d) Nothing

Correct answer is (b)

Your score on this question is: 0.00

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



Go to top of assessment.

Total score: 80.00



Your performance was as follows:

1.
Which of the following indicates the reaction time, in general, for searching in an open addressing hash table of size 1,000,000 with a load factor of 0.9?

(a) It will be almost instantaneous.
(b) It may fail to find an element that is present.
(c) It will be noticeably slow.
(d) It may "find" an element that is no longer there.

Correct answer is (c)

Your score on this question is: 10.00

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



2.
What is the purpose of using memoizing?

(a) To improve the memory requirements of hash tables
(b) To store return values of functions, in order to avoid recomputation
(c) To speed up access in a hash table
(d) To eliminate recursion in computing function values

Correct answer is (b)

Your score on this question is: 10.00

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



3.

Consider the following outline of a memoized function.

      int  f( int x ) { ... }

How many steps does it take to make 10000 calls to f on input x = 1000?



(a) About 10000 steps
(b) About 10000 steps, plus computing f(1000)
(c) A small, constant number of steps
(d) About 10000 times the number of steps used in computing f(1000)

Correct answer is (b)

Your score on this question is: 10.00

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



4.
What order should be expected when the occupied slots in an open addressing hash table with load factor 0.9 are printed in the order in which they appear in the table?

(a) Ascending order
(b) Blocks of items in ascending order
(c) Descending order
(d) Random order

Correct answer is (d)

Your score on this question is: 10.00

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



5.
In order for the division method to work in the context of hashing, the table size should be

(a) a prime
(b) anything but a prime
(c) a perfect square
(d) a power of two

Correct answer is (a)

Your score on this question is: 10.00

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



6.
When the load factor in a hash table becomes too high, the table must be resized. What should happen with the old entries?

(a) All the old entries should go into the same positions they occupied in the old table.
(b) The old entries should be spread out in the new table (e.g., if the new table is twice as large, an old entry at slot p should be moved to slot 2*p).
(c) They go into the slots that result from recomputing all the hash values.
(d) The resize command for the underlying array will take care of everything.

Correct answer is (c)

Your score on this question is: 10.00

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



7.
Which of the following correctly indicates where keys and associated values are stored in hash tables when open addressing is used?

(a) Each key is stored in a slot in the table, and the associated value is stored in one of the slots that follow.
(b) The keys are stored in the list header, and the associated values are stored in linked lists.
(c) Each key/value pair is stored in the table.
(d) The values are stored in a slot in the table, and keys are stored in the slots that follow.

Correct answer is (c)

Your score on this question is: 10.00

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



8.
The appropriate return type for a search function on a chaining hash table is

(a) a Boolean
(b) a pair consisting of a Boolean and an iterator
(c) a list node
(d) an iterator

Correct answer is (b)

Your score on this question is: 10.00

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



9.
For a templated hash table to cope with some user-defined key type Thing, the user has to specify

(a) the type Thing and a hash function for Thing.
(b) just the type Thing.
(c) just the size of the table, templates take care of the rest.
(d) the type Thing, a hash function for Thing, and equality testing for Thing.

Correct answer is (d)

Your score on this question is: 10.00

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



10.

Consider the following definition of a function hash.

      size_t  hash( const char *str )
      {
          size_t  h = 0;
          for( ; *str != '0'; str++ )
               h += *str;
      }

What, if anything, is wrong with hash as a hash function for null-terminated strings?



(a) Nothing
(b) All permutations of a word hash to the same slot.
(c) It makes no sense to add characters.
(d) If the string is very long, there will be overflow.

Correct answer is (b)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.
In the context of hashing, what is meant by a collision?

(a) Two key/value pairs have the same value.
(b) Two different keys hash to the same slot.
(c) The hash function returns a value larger than the table size.
(d) The insertion algorithm cannot find an empty slot in the table.

Correct answer is (b)

Your score on this question is: 10.00

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



2.
Which of the following is true about a good hash function?

(a) It should produce apparently random values for given items.
(b) It should never output a prime number.
(c) It should produce small outputs for small inputs.
(d) It should only output prime numbers.

Correct answer is (a)

Your score on this question is: 10.00

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



3.

Suppose a user-defined hash function has the following prototype.

      size_t  hash( const Thing& x );

Suppose further that it produces values of size up to 32 bits. To use this function with a hash table of size m, the user should



(a) compute hash( x ) / m
(b) compute hash( x ) % m
(c) modify x until a value less than m appears
(d) call the function repeatedly until a value less than m appears

Correct answer is (b)

Your score on this question is: 10.00

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



4.
Which of the following indicates the reaction time, in general, for searching in an open addressing hash table of size 1,000,000 with a load factor of 0.9?

(a) It may "find" an element that is no longer there.
(b) It will be almost instantaneous.
(c) It will be noticeably slow.
(d) It may fail to find an element that is present.

Correct answer is (c)

Your score on this question is: 10.00

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



5.

Consider the following outline of a memoized function.

      int  f( int x ) { ... }

How many steps does it take to make 10000 calls to f on input x = 1000?



(a) About 10000 steps, plus computing f(1000)
(b) About 10000 times the number of steps used in computing f(1000)
(c) A small, constant number of steps
(d) About 10000 steps

Correct answer is (a)

Your score on this question is: 10.00

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



6.
In order for the division method to work in the context of hashing, the table size should be

(a) anything but a prime
(b) a power of two
(c) a perfect square
(d) a prime

Correct answer is (d)

Your score on this question is: 10.00

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



7.
When the load factor in a hash table becomes too high, the table must be resized. What should happen with the old entries?

(a) All the old entries should go into the same positions they occupied in the old table.
(b) The resize command for the underlying array will take care of everything.
(c) They go into the slots that result from recomputing all the hash values.
(d) The old entries should be spread out in the new table (e.g., if the new table is twice as large, an old entry at slot p should be moved to slot 2*p).

Correct answer is (c)

Your score on this question is: 10.00

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



8.
Which of the following correctly indicates where keys and associated values are stored in hash tables when chaining is used?

(a) Each key is stored in the table, and the associated value is stored in a linked list.
(b) The keys are stored in the table, and the associated values are stored in the list header.
(c) Each key/value pair is stored in a node of a linked list.
(d) The keys are stored in the list header, and the associated values are stored in the linked lists.

Correct answer is (c)

Your score on this question is: 10.00

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



9.
Which of the following correctly indicates where keys and associated values are stored in hash tables when open addressing is used?

(a) Each key is stored in a slot in the table, and the associated value is stored in one of the slots that follow.
(b) The keys are stored in the list header, and the associated values are stored in linked lists.
(c) Each key/value pair is stored in the table.
(d) The values are stored in a slot in the table, and keys are stored in the slots that follow.

Correct answer is (c)

Your score on this question is: 10.00

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



10.

Consider the following definition of a function hash.

   size_t  hash( const char *str )
      {
          size_t  h = 0;
          for( ; *str != '0'; str++ )
               h = h*256 + *str;
      }

What, if anything, is wrong with hash as a hash function for null-terminated strings?



(a) It is very slow to compute.
(b) If the string is very long, there will be overflow.
(c) It only takes into account the last few characters long strings.
(d) Nothing

Correct answer is (c)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 100.00



Your performance was as follows:

1.
Suppose hash() is a hash function. The main idea behind hashing is to use a key k to store a value v in which position of a table?

(a) hash(k)
(b) hash() (a random position computed by the hash function using k)
(c) hash(k,v)
(d) hash(v)

Correct answer is (a)

Your score on this question is: 10.00

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



2.
If a hash table of size m contains n items, what is the load factor of the table?

(a) m - n
(b) n + m
(c) n/m
(d) m/n

Correct answer is (c)

Your score on this question is: 10.00

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



3.
Which of the following is true about a good hash function?

(a) It should never output a prime number.
(b) It should produce apparently random values for given items.
(c) It should only output prime numbers.
(d) It should produce small outputs for small inputs.

Correct answer is (b)

Your score on this question is: 10.00

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



4.
Which of the following indicates the reaction time, in general, for searching in a chaining hash table of size 1,000,000 with a load factor of 0.9?

(a) It will be almost instantaneous.
(b) It may fail to find an element that is present.
(c) It may "find" an element that is no longer there.
(d) It will be noticeably slow.

Correct answer is (a)

Your score on this question is: 10.00

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



5.
In searching for an entry with key k in a chaining hash table, the slot p = hash(k) is computed, after which it is necessary to

(a) check if the entry in slot p, or p+1, p+2, and so forth, has key k
(b) check if the entry in slot p has key k
(c) traverse a linked list to check if any entry there has key k
(d) compute p + k to find the right position for the entry

Correct answer is (c)

Your score on this question is: 0.00

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



6.
What is the purpose of using memoizing?

(a) To store return values of functions, in order to avoid recomputation
(b) To improve the memory requirements of hash tables
(c) To eliminate recursion in computing function values
(d) To speed up access in a hash table

Correct answer is (a)

Your score on this question is: 10.00

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



7.

Consider the following outline of a memoized function.

      int  f( int x ) { ... }

How many steps does it take to make 10000 calls to f on input x = 1000?



(a) About 10000 steps, plus computing f(1000)
(b) About 10000 steps
(c) A small, constant number of steps
(d) About 10000 times the number of steps used in computing f(1000)

Correct answer is (a)

Your score on this question is: 10.00

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



8.
Which of the following correctly indicates where keys and associated values are stored in hash tables when open addressing is used?

(a) The values are stored in a slot in the table, and keys are stored in the slots that follow.
(b) Each key/value pair is stored in the table.
(c) Each key is stored in a slot in the table, and the associated value is stored in one of the slots that follow.
(d) The keys are stored in the list header, and the associated values are stored in linked lists.

Correct answer is (b)

Your score on this question is: 10.00

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



9.
The appropriate return type for a search function on a chaining hash table is

(a) a pair consisting of a Boolean and an iterator
(b) a list node
(c) an iterator
(d) a Boolean

Correct answer is (a)

Your score on this question is: 10.00

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



10.

Consider the following definition of a function hash.

      size_t  hash( const char *str )
      {
          size_t  h = 0;
          for( ; *str != '0'; str++ )
               h += *str;
      }

What, if anything, is wrong with hash as a hash function for null-terminated strings?



(a) It makes no sense to add characters.
(b) If the string is very long, there will be overflow.
(c) Nothing
(d) All permutations of a word hash to the same slot.

Correct answer is (d)

Your score on this question is: 10.00

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



Go to top of assessment.

Total score: 90.00