Deck 16: Standard Library Algorithms
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/27
Play
Full screen (f)
Deck 16: Standard Library Algorithms
1
The easiest way to search through a list of names and output the first one that begins with a vowel would be to use function:
A) find
B) find_if
C) sort
D) binary_search
A) find
B) find_if
C) sort
D) binary_search
B
2
Lambdas return types ________.
A) cannot be inferred.
B) can be inferred automatically if the body is a single statement of the form return expression; otherwise, the return type is void by default.
C) are always void.
D) None of the above.
A) cannot be inferred.
B) can be inferred automatically if the body is a single statement of the form return expression; otherwise, the return type is void by default.
C) are always void.
D) None of the above.
B
3
A lambda function can capture local variables ________ and manipulate them inside the lambda's body.
A) by value.
B) by reference.
C) by value or by reference.
D) None of the above.
A) by value.
B) by reference.
C) by value or by reference.
D) None of the above.
C
4
Functions iter_swap and swap_ranges are similar in that both:
A) Swap a range of elements.
B) Take two arguments.
C) Take forward iterators as arguments.
D) Can only swap elements within the same array or container.
A) Swap a range of elements.
B) Take two arguments.
C) Take forward iterators as arguments.
D) Can only swap elements within the same array or container.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
5
Function mismatch returns:
A) The position number where the two specified sequences do not match.
B) A pair containing the two elements in the specified sequences that do not match.
C) A pair containing two iterators pointing to the two locations in the specified sequences that do not match.
D) A bool indicating whether the two specified sequences do not match.
A) The position number where the two specified sequences do not match.
B) A pair containing the two elements in the specified sequences that do not match.
C) A pair containing two iterators pointing to the two locations in the specified sequences that do not match.
D) A bool indicating whether the two specified sequences do not match.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
6
The order of the arguments passed to function replace_copy_if must be:
A) OutputIterator, InputIterator, ReplacementValue, PredicateFunction.
B) InputIterator, OutputIterator, PredicateFunction, ReplacementValue.
C) OutputIterator, InputIterator, InputIterator, ReplacementValue, PredicateFunction.
D) InputIterator, InputIterator, OutputIterator, PredicateFunction, ReplacementValue.
A) OutputIterator, InputIterator, ReplacementValue, PredicateFunction.
B) InputIterator, OutputIterator, PredicateFunction, ReplacementValue.
C) OutputIterator, InputIterator, InputIterator, ReplacementValue, PredicateFunction.
D) InputIterator, InputIterator, OutputIterator, PredicateFunction, ReplacementValue.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
7
Function template back_inserter returns:
A) A container.
B) An iterator for a container.
C) An element in a container.
D) A reference to an element in a container.
A) A container.
B) An iterator for a container.
C) An element in a container.
D) A reference to an element in a container.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
8
Given that v1 and v2 are vectors, what is returned by the function call std::equal(v1.begin(), v1.end(), v2.begin())
A) A bool indicating whether v1 and v2 are equal.
B) A bool indicating whether the first element of v1, the last element of v1 and the first element of v2 are all equal.
C) An iterator pointing to the first location where v1 and v2 are equal.
D) An iterator pointing to the first location where v1 and v2 are not equal.
A) A bool indicating whether v1 and v2 are equal.
B) A bool indicating whether the first element of v1, the last element of v1 and the first element of v2 are all equal.
C) An iterator pointing to the first location where v1 and v2 are equal.
D) An iterator pointing to the first location where v1 and v2 are not equal.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
9
The easiest way to set all the values of a vector to zero is to use function:
A) fill
B) fill_n
C) generate
D) generate_n
A) fill
B) fill_n
C) generate
D) generate_n
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
10
Lambdas begin with the lambda introducer ________, followed by a parameter and function body.
A) []
B) ()
C) {}
D) <>
A) []
B) ()
C) {}
D) <>
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
11
Suppose you have a shopping list stored in a vector. What function would you use to remove all items in that vector that are under 10 dollars and place them in another container?
A) remove
B) remove_copy
C) remove_if
D) remove_copy_if
A) remove
B) remove_copy
C) remove_if
D) remove_copy_if
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
12
Which of the following is a valid generator function prototype for use with generate or generate_n on a vector?
A) void nextLetter();
B) char nextLetter();
C) char nextLetter(char);
D) char nextLetter(int);
A) void nextLetter();
B) char nextLetter();
C) char nextLetter(char);
D) char nextLetter(int);
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
13
Which of the following statements produces the same results as the statement: std::copy(v1.begin(), v1.end(), v2.begin());
If v1 and v2 are both 10-element vectors?
A) std::copy_backward(v1.begin(), v1.end(), v2.begin());
B) std::copy_backward(v2.begin(), v2.end(), v1.begin());
C) std::copy_backward(v1.begin(), v1.end(), v2.end());
D) std::copy_backward(v2.begin(), v2.end(), v1.end());
If v1 and v2 are both 10-element vectors?
A) std::copy_backward(v1.begin(), v1.end(), v2.begin());
B) std::copy_backward(v2.begin(), v2.end(), v1.begin());
C) std::copy_backward(v1.begin(), v1.end(), v2.end());
D) std::copy_backward(v2.begin(), v2.end(), v1.end());
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
14
Which of the following function calls is a valid way to place elements into vector chars?
A) std::fill(chars.begin(), chars.end(), '5');
B) std::fill_n(chars.begin(), chars.end(), '5');
C) std::generate(chars.begin(), 10, '5');
D) std::generate_n(10, chars.end(), '5');
A) std::fill(chars.begin(), chars.end(), '5');
B) std::fill_n(chars.begin(), chars.end(), '5');
C) std::generate(chars.begin(), 10, '5');
D) std::generate_n(10, chars.end(), '5');
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
15
Which algorithm cannot take a predicate function as an argument?
A) find
B) find_if
C) sort
D) binary_search
A) find
B) find_if
C) sort
D) binary_search
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
16
Which of the following statements is false?
A) With the C++14 version of the equal algorithm to compare two sequences of values for equality, the second sequence must contain at least as many elements as the first-equal returns false if the sequences are not of the same length.
B) With the C++14 version of the mismatch algorithm to compare two sequences of values, the algorithm returns a pair of iterators indicating the location in each sequence of the first mismatched elements. If all the elements match, the two iterators in the pair are equal to the end iterator for each sequence.
C) Always use C++11's versions of equal and mismatch - these are preferred because they compare the lengths of the ranges for you, eliminating a potential source of logic errors.
D) In C++14, use = rather than braces when initializing a variable declared with auto.
A) With the C++14 version of the equal algorithm to compare two sequences of values for equality, the second sequence must contain at least as many elements as the first-equal returns false if the sequences are not of the same length.
B) With the C++14 version of the mismatch algorithm to compare two sequences of values, the algorithm returns a pair of iterators indicating the location in each sequence of the first mismatched elements. If all the elements match, the two iterators in the pair are equal to the end iterator for each sequence.
C) Always use C++11's versions of equal and mismatch - these are preferred because they compare the lengths of the ranges for you, eliminating a potential source of logic errors.
D) In C++14, use = rather than braces when initializing a variable declared with auto.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
17
If v1 is a vector containing some number of int elements sorted in ascending order, after these statements execute: std::vector results1;
Std::vector results2;
Std::unique_copy(v1.begin(), v1.end(), std::back_inserter(results1));
Std::reverse_copy(v1.begin(), v1.end(), std::back_inserter(results2));
Which of the following could be true?
A) results1 contains more elements than results2.
B) The first element in results1 matches the last element in results2.
C) results1 is empty but results2 is not.
D) None of the above.
Std::vector
Std::unique_copy(v1.begin(), v1.end(), std::back_inserter(results1));
Std::reverse_copy(v1.begin(), v1.end(), std::back_inserter(results2));
Which of the following could be true?
A) results1 contains more elements than results2.
B) The first element in results1 matches the last element in results2.
C) results1 is empty but results2 is not.
D) None of the above.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
18
Which of the following is not a mathematical algorithm included in the Standard Library?
A) min_element
B) copy
C) transform
D) accumulate
A) min_element
B) copy
C) transform
D) accumulate
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
19
The for_each function applies a general function to each element in the specified range. This general function should:
A) Take an argument of the elements' type and return nothing.
B) Take an argument of the elements' type and return a value of the elements' type.
C) Take an argument of a non-const reference to the elements' type and return nothing.
D) Take an argument of a non-const reference to the elements' type and return a value of the elements' type.
A) Take an argument of the elements' type and return nothing.
B) Take an argument of the elements' type and return a value of the elements' type.
C) Take an argument of a non-const reference to the elements' type and return nothing.
D) Take an argument of a non-const reference to the elements' type and return a value of the elements' type.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
20
The algorithms in the Standard Library:
A) Use virtual function calls.
B) Are implemented as member functions of the container classes.
C) Do not depend on the implementation details of the containers on which they operate.
D) Are not as efficient as the algorithms presented in most textbooks.
A) Use virtual function calls.
B) Are implemented as member functions of the container classes.
C) Do not depend on the implementation details of the containers on which they operate.
D) Are not as efficient as the algorithms presented in most textbooks.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
21
Functions lower_bound, upper_bound and equal_range are different in their:
A) Return types.
B) First argument types.
C) Second argument types.
D) Third argument types.
A) Return types.
B) First argument types.
C) Second argument types.
D) Third argument types.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following function calls would not return the value that is its first argument?
A) std::min(3, 23)
B) std::min('N', 'P')
C) std::max(17, 16)
D) std::max('d', 'k')
A) std::min(3, 23)
B) std::min('N', 'P')
C) std::max(17, 16)
D) std::max('d', 'k')
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
23
The __________ function would produce a sequence containing three elements when passed the sequences 1, 2 and 1, 2, 3, 4, 5 as first/second and third/fourth arguments, respectively.
A) set_intersection
B) set_difference
C) set_union
D) set_symmetric_difference
A) set_intersection
B) set_difference
C) set_union
D) set_symmetric_difference
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
24
The __________ function would produce the sequence 1, 5, 6 when passed the sequences 1, 2, 3, 4, 5, 6 and 2, 3, 4, 7 as first/second and third/fourth arguments, respectively.
A) set_intersection
B) set_difference
C) set_union
D) set_symmetric_difference
A) set_intersection
B) set_difference
C) set_union
D) set_symmetric_difference
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
25
Which of the following is not true of a class that will be used to instantiate function objects?
A) It must overload the parentheses operator.
B) It can have data members.
C) It must be a concrete class.
D) All of the above are true about a class that will be used to instantiate function objects.
A) It must overload the parentheses operator.
B) It can have data members.
C) It must be a concrete class.
D) All of the above are true about a class that will be used to instantiate function objects.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following is not a category of the Standard Library algorithms?
A) mutating sequence algorithms
B) sorting and related algorithms
C) generalized numeric operations
D) All of the above are categories of the Standard Library Algorithms.
A) mutating sequence algorithms
B) sorting and related algorithms
C) generalized numeric operations
D) All of the above are categories of the Standard Library Algorithms.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
27
Function objects have their functions called by using:
A) The dot operator (.)
B) operator()
C) The arrow operator (->)
D) The binary scope resolution operator (::)
A) The dot operator (.)
B) operator()
C) The arrow operator (->)
D) The binary scope resolution operator (::)
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck