Студопедия

КАТЕГОРИИ:

АстрономияБиологияГеографияДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРиторикаСоциологияСпортСтроительствоТехнологияФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника


c) Advances the iterator to the next item.




C) Steps the iterator backwards to the previous item.

(d) Post-decrements the item to which the iterator points.

 

30. Access to ranges of elements in an STL container is typically handled by

(a) iterators

(b) pointers

(c) suitable access member functions

(d) references

31. 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) Advances the iterator to the next item.

(d) Increase by 1 the size of the container

pointed to by it.

32.

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

 

  2.   Execution of which of the following statements sets an STL iterator it so that it points to the first element of a container A?  

 

  (a) A.reset( it ); (b) A.begin( it ); (c) begin( A, it ); (d) it = A.begin();

 

  3.   The main abstractions of the Standard Template Library include which of the following? I. Iterators II. Exception handlers III. Algorithms  

 

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

 

  4.   A typical implementation of a deque in the C++ STL minimizes the need to copy elements upon the frontal insertion of new items by  

 

  (a) inserting the element at the end of the deque and maintaining a table of element positions (b) using a background thread to reallocate memory when necessary (c) reserving memory at the front of the deque's stored elements (d) inserting the element at the next available position in the deque and maintaining a table of element positions

 

  5.   In the C++ Standard Template Library, vectors and deques differ in their interfaces for handling which of the following operations? I. Insertion of an element at the front of the container II. Insertion of an element at the end of the container III. Removal of an element from the front of the container  

 

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

 

  6.   In STL vectors, _____ refers to the maximum number of items that can be stored without resizing, and _____ refers to the number of items stored.  

 

  (a) range, domain (b) capacity, size (c) size, capacity (d) domain, range

 

  7.   Consider the following declaration that makes use of a user-defined class Thing. vector<Thing> A(10); In order that it compile, the class Thing must have which of the following?  

 

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

 

  8.   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) 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

 

  9.   Consider the following C++ program segment, assuming that string is a class. string str1("Hello, World"); str1[5] = 'Z'; The overloaded operator[] function invoked in the above program segment should have which of the following return types?  

 

  (a) char & (b) char (c) char * (d) const char &

 

  10.   Which of the following statements is (are) true regarding C-style strings? I. They are terminated by the null character. II. Storing a five-character string requires at least seven characters.  

 

  (a) II only (b) I only (c) None (d) I and II
1.   Consider the following C++ program segment, which uses the STL. stack<int> X;X.push(2);X.push(14);X.pop();X.push(37);X.push(40);X.pop();cout << X.top(); What is the output when this program segment is executed?  
           

 

  (a) 2 (b) 40 (c) 14 (d) 37

 

  2.   The queue adapter interface in the C++ Standard Template Library contains which of the following member functions? I. push II. pop_back  

 

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

 

  3.   An STL adapter provides  

 

  (a) a network-socket interface to an STL container (b) a pointer to an instance of an STL container (c) a wrapper that allows an STL container to be used by the Java programming language (d) a new programming interface for an existing STL container

 

  4.   Which of the following operations typically removes an item from a stack?  

 

  (a) push (b) empty (c) top (d) pop

 

  5.   Which of the following is (are) typically managed using a stack? I. Implementation of function calls in a procedural programming language II. Evaluating arithmetic expressions, taking precedence rules into account III. Handling jobs sent to a printer, and ensuring that the first jobs to be submitted are printed first  

 

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

 

  6.   Which of the following is not a basic operation that can be performed on a queue?  

 

  (a) Inserting an item into the second position of the queue (b) Inserting an item at the back of the queue (c) Accessing an item from the front of the queue (d) Removing an item from the front of the queue

 

  7.   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) inserting a new element 10 after each list element (c) stepping through the lists in increments of 10 (d) adding 10 to each list element

 

  8.   Typical implementations for which of the following STL containers store elements contiguously in memory? I. vector II. list  

 

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

 

  9.   To access an element in a singly linked list, a program must  

 

  (a) traverse all nodes in the list prior to that element (b) allocate memory for temporary nodes (c) add the element's index to the memory address of the first element in the list (d) compute a hash value for the element

 

  10.   A singly linked list is a linked list in which  

 

  (a) elements must contain unique values (b) each node contains a pointer to only one other node (c) a single use of the operator new allocates memory for the list (d) elements can contain duplicate values
1.   How many calls to itself is a recursive function allowed to make?  
           

 

  (a) None (b) At most one (c) At most two (d) Any number

 

  2.   Consider the following definition of a recursive function ff in C++. int ff( int n, int m ){ if( n == 0 ) return m; return ff( n - 1, m + 1 );} Which of the following characterizes the value returned by the call f(n,m)?  

 

  (a) The sum of m and n (b) The product of m and n (c) The greatest common divisor of m and n (d) The least common multiple of m and n

 

  3.   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) even (b) a prime (c) a power of 2 (d) odd

 

  4.   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) even (b) non-negative (c) odd (d) unrestricted

 

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

 

  6.   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 all odd inputs x only (c) For x = 0 only (d) For all inputs x

 

  7.   Which of the following is (are) true of the minimax strategy for deciding the optimal move in a two-person game? I. It assumes that a human player will eventually make a mistake by playing a move that is not optimal. II. It is commonly used with a backtracking algorithm.  

 

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

 

  8.   A backtracking algorithm is one that  

 

  (a) uses recursion to test all possible solutions for a problem (b) uses a binary search to solve a problem (c) uses loops to iterate through all possible solutions for a problem (d) splits a problem into two equal halves and uses recursion to solve each half

 

  9.   Typical divide and conquer algorithms use _____ to divide a problem into smaller sub-problems. The _____ typically solve(s) these sub-problems directly.  

 

  (a) inheritance, methods of the child class (b) iteration, body of the loop (c) a process scheduler, individual processes (d) recursive function calls, base case of the recursion

 

  10.   What is the runtime overhead of a divide-and-conquer algorithm that recursively processes two equal halves of a problem that each have an overhead of O(n)?  

 

  (a) O(n2) (b) O(log n) (c) O(2n) (d) O(n log n)
1.   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 by applying function f to its elements. (b) Container A is sorted using sorting algorithm f. (c) Container A is sorted using the Boolean valued function f for comparisons. (d) Container A is sorted using the function f for assignments.

 

  2.   Which of the following statements is true of the selection-sort algorithm? I. It is a divide-and-conquer algorithm typically implemented using recursion. II. An implementation of the algorithm typically requires the use of a hash table.  

 

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

 

  3.   Which of the following search algorithms can be applied to unsorted data? I. Linear search II. Binary search  

 

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

 

  4.   Consider a data set of 100 items. Which of the following is a search algorithm (are search algorithms) that could possibly examine 25 items in this set before succeeding? I. Linear search II. Binary search  

 

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

 

  5.   What is the purpose of using memoizing?  

 

  (a) To improve the memory requirements of hash tables (b) To speed up access in a hash table (c) To store return values of functions, in order to avoid recomputation (d) To eliminate recursion in computing function values

 

  6.   Which of the following indicates the primary difficulty with hashing in general?  

 

  (a) Hash functions are hard to compute. (b) Collisions will occur. (c) Access in hash tables is slow. (d) Hash tables take up a lot of memory.

 


Поделиться:

Дата добавления: 2015-09-15; просмотров: 81; Мы поможем в написании вашей работы!; Нарушение авторских прав





lektsii.com - Лекции.Ком - 2014-2024 год. (0.007 сек.) Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав
Главная страница Случайная страница Контакты