Week 6 of the course

Self-study

The topics for this week are the following: (i) STL algorithms (ii) Lambda functions and (iii) Tuning STL algorithms and containers

The following links will take you to the video-lectures and the accompanying slides:

STL algorithms

Suppose one has some STL container in variable \(A\) and one wishes to input \(A\) into an STL algorithm \(X\). What parameter (or parameters) would one input to \(X\) to indicate that one wishes \(X\) to use the entire container \(A\)?
For what reasons is it better to use algorithms from the STL library to compute some task rather than writing your own algorithms for computing the task? (There may be more than 1 correct reason.)

STL algorithms - examples

Suppose begin and end are two iterators associated with vector v. Suppose the location to the right of begin is \(i\) and the location to the right of end is \(j\). What is the significance of the difference end - begin?
Which of the following is true about the STL algorithsm?

Lambda functions

Suppose in C++ one has a vector std::vector<int> v{6, 3, 4, 9, 2, 7, 1, 11};. Which of the following will result in *it having a value of 2?
Regarding lambda functions, which of the following statements are true? (More than 1 may be true.)
Suppose in C++ one has a vector std::vector<int> v{-19, 21, -4, 6};. What will be the value of *it when the following is executed?:: auto it = std::find_if(begin(v), end(v), [](int i){ return (i%2 != 0 && i >0); });

Lambda functions and variable captures

When we say a lambda function captures a variable we mean
Suppose in C++ one has a vector v of integers and d is some nonzero integer. What will be the value of a when the following is executed?:: int a = std::count_if(v.begin(), v.end(), [d](int i){return (i % d != 0 && i*d > 0 );});

Tuning STL algorithms and containers

Which of the following statements, regarding tuning of STL algorithms, is true? (More than one statement may be true.)
The STL contains algorithms named count_if, find_if and remove_if. Which of the following properties do all these algorithms have?
What is a central question, related to this course, whose answer can be found in this week’s videos?
Of the following topics, which do you think deserves further discussion/explanation during the weekly consultation session?
Were there any parts of the video lectures that were particularly difficult? Particularly interesting? Something about which you wish to learn more?

Extra links on the topic:

Week06 - Glossary

Homework to be returned for the weekly exercises

Questions to be submitted this week