Test 1

Date & Time

Wednesday, October 4, 9:30-10:45am, PM 110

Overview

Test 1 will cover all material from the beginning of the semester through container adapters. This material includes everything discussed in lectures and covered in assignments. You should know concepts (e.g. what an iterator is, how Big-O notation works) as well as syntax. You may be asked to write, analyze, and/or debug code.

Format

  • Multiple Choice
  • Free Response

Topics

  • C++ Syntax
  • STL Containers
  • Sequential Containers
  • Associative Containers
  • Iterators
  • Algorithms
  • Algorithm Complexity
  • Templates
  • Higher-Order Functions
  • Container Adapters
  • Iterator Adapters
  • Git and GitHub

Example Types of Free-Response Questions

  • Given a block of code, locate all errors and detail how you would fix them. For example,
    var output;
    vector v = {1.2, 3.4, 5.6};
    for (int i = 0; i < v.length; i++) {
        output.append(i ** 2);
    }
  • What are the three components of the STL?
  • How do iterators reduce the amount of code the STL must maintain?
  • Which container would work best for storing and looking up state names by their abbreviations? Why?
  • For which operations is a list more efficient than a deque?
  • Given the following code, what is its complexity in Big-O notation?
    // existing vector v with n elements
    for(int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v.size(); j++) {
            v.insert(v.begin(), v[i] * v[j]);
        }
    }
  • Given that the random_shuffle algorithm takes two random access iterators as arguments, which of the sequenetial containers can be shuffled using that algorithm?
  • Write a lambda expression (to replace <EXPRESSION> below) that uses find_if to compare all elements from a vector v to find the first value greater than threshold
    // existing vector<int> v
    int threshold;
    cin >> threshold;
    auto it find_if(v.begin(), v.end(), <EXPRESSION>);
  • What is the advantage of the auto keyword? When is it used?
  • If one function uses \(3n^2\) operations and another uses \(5(n-1)^2\) operations, how are they related in terms of Big-O notation?
  • What do Big-\(\Theta\) and Big-\(\Omega\) measure?
  • What is the difference between a priority queue and a queue?
  • What type of iterators does a stack provide?