==== Question ==== Answer the following questions: a) Pick two STL algorithms (not std::for_each) from your solution of the previous assignment and explain why those two algorithms are suitable choices. b) Give an example of an algorithm that can only operate on RandomAccess iterators. Why do you think it only works for RandomAccess iterators? ==== Answer ==== a) I picked std::iota and std::accumulate. std::iota: is suitable since we are trying to fill a non-empty vector with consecutive integer values. This is exactly what std::iota does so it is quite appropriate. Note however that this is only suitable since we *know* the number of elements that will be needed. std::accumulate: At the end of the program we want to combine all factors into one number by multiplying them together. This can be done with a for-loop (or std::for_each) but then we need to keep track of the current product, which means more code than necessary since std::accumulate already solves all of these problems for us. We can just use std::accumulate + std::multiplies for this purpose, which is quite suitable since it clearly communicates the intent. b) std::sort only works with RandomAccess iterators. The reason for this is that efficient sorting algorithms (algorithms with complexity O(n log n)) requires us to be able to jump to arbitrary elements in constant time, and since std::sort has the required time complexity of O(n log n) we cannot use "inefficient" sorting algorithms.