View Assessment Result: Multiple Choice Quiz 9



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