View Assessment Result: Multiple Choice Quiz 9



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