Final Exam

The final exam is Tues Dec 8, 8-10 AM. It is in our normal classroom. The format for the exam will be very similar to the previous two exams (but with different content). The final is cumulative so anything from the entire course can be on the exam. Having said that, roughly 60%-70% of the questions will be from material from Day 30 through the end of the course (this is material that did not appear on Exam 1 or Exam 2).

Content

Sample Questions

Try not to look at the following and do it yourself, but here I will give you the solution to writing a count_positive method on a binary tree.

Say the struct I gave you was:

struct StringIntTree {
    struct Node {
        shared_ptr<Node> left;
        shared_ptr<Node> right;
        string key;
        int val;
    };
    shared_ptr<Node> root;
};

The problem is to write a count_positive method which counts the number of values which are positive. The solution is as follows:

int count_helper(shared_ptr<Node> n) {
    if (!n) {
        return 0;
    }
    int leftCount = count_helper(n->left);
    int rightCount = count_helper(n->right);
    if (n->val > 0) {
        return leftCount + rightCount + 1;
    } else {
        return leftCount + rightCount;
    }
}
int count() {
    return count_helper(root);
}