Chapter 18 Quiz

Ace your homework & exams now with Quizwiz!

A failing find() operation on an STL set returns a null pointer value.

False

The runtime for insertion at any position into a vector is O(1).

False

You cannot copy stacks.

False

Order of magnitude estimates don't work well if we are interested in behavior for small data sets.

True

STL set operations are essentially insert, delete, and the query, "Is it there?".

True

The STL containers each define iterators appropriate to the internal structure of the container.

True

The associative containers store their data in an order different from the insertion order.

True

The model for the iterator in the STL was the pointer.

True

The notation m["stringval"] = 100 is valid if m is a map that takes a pair of type (string, int).

True

To declare an iterator, one must #include the proper header file, then specify the container type and use that with the scope resolution operator, ::, to qualify the inner type iterator, to declare the iterator variable, as in #include <vector> std::vector<int>::iterator myIterator;.

True

In which container does the position of an inserted element depend on the data, NOT the order of insertion?

a) associative containers

Which of the following operations do bidirectional iterators have?

a) prefix operator* to make available the container element for use as l-value or r-value

Which of the following operations do random access iterators have?

a) prefix operator* to make available the container element for use as l-value or r-value

Which of the following is NOT, strictly speaking, a component of the Standard Template Library?

a) templates

Suppose we have the following definition: vector<int> vec, vec1; //use push_back to put 10 values into vec vector<int>::iterator p = vec.begin(); vector<int>::const_iterator q = vec.begin(); Which of the following expressions is NOT legal? Treat the effect of these as non-cumulative.

b) *q = 1;

I have an algorithm that runs in O(N 1/2), where n is the size of the problem. For N = 100, the time the algorithm runs is 1 minute. How long does the algorithm take for N=1000?

b) About 3 minutes

The expression, 4N 2-2N+1 is

b) Quadratic (degree 2)

Which of the following does NOT have STL containers types?

b) generic functions

Which of the following is an incorrect declarations of iterators for STL containers? You may assume that the proper header has been included and that a using directive makes the names from namespace std available.

b) list::iterator<int> listIterator;

I have an algorithm that runs in O(N 2), where Nis the size of the problem. For N = 100, the time for the algorithm to run is 1 minute. How long does the algorithm take for N=1000?

c) 100 minutes

The time to find an element is the same for a set or a map. It is

c) O(log N)

I have an algorithm that runs in O(n 2)time, where n is the size of the problem. What does "the size of the problem" mean?

c) The size of a problem is the number of data items that the algorithm operates upon.

Given the following definition for a map, which code fragment will correctly iterate through the map and output each item? map<int, string> mymap;

c) for (auto item : mymap) cout << item.first << " " << item.second << endl;

Which of the following is NOT a member function of the stack adapter template? For members of stack, specify any needed arguments.

c) front()

Suppose we have the following definition: vector<int> vec; // use push_back to put 10 values into vec here. vector<int>::iterator itr1, itr2,itr3; itr1 = vec.begin(); itr2 = vec.begin() + 5; itr3 = vec.end(); For this iterator which of the following is incorrect?

c) itr3 + 3

Given the following definition for a map, which code fragment is valid? map<int, string> mymap;

c) mymap[10] = "hello";

Which of the following operations do forward iterators have?

c) overloaded operator++ to move the place the iterator points forward by one element

The operator * is prefixed to an iterator to

d) extract the element in the container as either an l-value or an r-value.

Which of the following member functions is NOT common to the sequential containers (vector, list, deque)?

d) push_front()

Which of the following is NOT a member function of the queue adapter template? For members of queue, specify any needed arguments.

e) top()


Related study sets

MOD 1: Chapter 16 Employment Communications

View Set

Chapter 12 The Arbitration Process

View Set