View Assessment Result: Multiple Choice Quiz 9



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