Skip to content

Instantly share code, notes, and snippets.

Last active July 16, 2020 05:54
What would you like to do?
CS61A Exam Tips (Summer 2020)

CS61A Exam Tips

Summer 2020

Table of Contents

  1. Categorization
  2. Skeleton Code
  3. Problem Solving
  4. Online Format


  • Read the question and look at the skeleton code to determine what topic is being tested

    • Is it iteration or recursion? Mutable or immutable lists?

    • Certain keywords or phrases in the prompt can give it away:

      • "foo is a function that takes in... and returns another function" → Higher Order Functions

      • "Count the number of ways..." → Tree Recursion

      • "Find the longest path..." → Tree Recursion + calling max on your recursive calls

    • Looking at input → output in the doctests can clarify the premise of the question (see Problem Solving)

    • Sometimes the question prompt will explicitly state what the intent is or is not

      • "Your solution must use recursion and should not modify the input list"

      • "You may not use str"

      • "Neither recursion nor containers are allowed in your solution"

  • Think about common problem solving strategies you've seen for this topic in lecture, lab, discussion, homework, etc.

    • e.g. For digit manipulation iteration, you typically parse the digit from right to left, do something with the last digit, n % 10, and n // 10 each iteration

    • e.g. For ADT Trees, you typically have a base case for is_leaf(t) and tree recurse through the sub-trees in the recursive case with for b in branches(t)

    • e.g. For nonlocal... use nonlocal :D

Skeleton Code

  • Look at the code that is already written for you

    • What are the parameters and what do they represent?

    • What are the variables that are already initialized for?

  • Use the indent structure and pre-filled lines to pattern match (think categorization!)

  • If you find skeleton code restrictive, try solving it in the way that's most intuitive to you first, then mold it to fit the skeleton

    • For the most part, with the inputs/information and constraints you're given, there's only one general way to solve the problem; the smaller details can be cleaned up when you go back to fill in the skeleton

    • With the online format, you can run your solution against the doctests even if it doesn't follow the skeleton

Problem Solving

  • Draw out a simple case

  • Draw out a slightly more complicated case

    • What changes? What extra factors do you have to account for with non-trivial inputs?

    • Try and work through this test case by hand without thinking about the code

      • Look back at your work and try to find Python analogs to each of the steps/sub-processes you underwent in your head to get to the final answer

        • e.g. "To find the height of a tree, I start at the top/root and trace each path downward until it ends, keeping track of how many nodes I've traversed along the way. Then, the length of the longest path is the height of the tree!"
      • If your method solving the problem by hand can be generalized for any reasonable input, it will work when converted to Python too!

  • Are there any assumptions that you can make? Sometimes they are explicitly stated in the prompt

  • See this guide for ways to deal with getting stuck

Checking your Work

  • Consider edge cases: n = 0, n = -1, lst = [], t = tree(1)

  • Remain consistent among your return types

    • For recursive problems especially, you pretty much never want mismatched return types

    • e.g. return label(t) vs return [label(t)]

  • For a more general and abstract (but just as helpful) approach to debugging, I highly recommend reading "How to Learn Computer Science" by Kevin Lin, a past CS61A summer instructor

Strategy differs a bit for the online format

Online Format

  • Run python3 ok often

    • This will backup your code on OKPY, so if you forget to submit, you won't just get a 0

    • You can test your code!!!

      • Don't waste your precious exam time working through test inputs in your head if you can just run OK!
  • Although the interpreter and internet can be useful for clarifying small Python quirks, you should really be spending most of your time trying to directly solve the problem

    • We aren't testing your Googling skills; the questions are designed to be solved without any outside resources
  • For topics like Trees, Tree Recursion, and Mutability, having scratch paper handy to sketch diagrams on will be invaluable

  • Pay close attention to the time

    • Individual question time limits are strict, and you do not have the option to distribute your exam time the way that you want

    • Set timers, use a stopwatch, set 5 minute warnings, etc. will include a timer that counts down the time left on your current question, so no need for a separate timer

  • Don't overthink it if you didn't get a question fully correct

    • Especially with the one-question-at-a-time rule, not solving a problem to your satisfaction within the 25 minute slot can very understandably be demoralizing and frustrating

    • Don't let this get to your head. The unfortunate fact of the matter is that you cannot change your answer anymore; the number of points that you will get for that question has essentially already been determined

    • The nice thing about this is that you don't have to worry about that problem anymore! What's done is done, and you don't have to plan for extra time at the end to go back and fix revise your answer. No more nagging thoughts in the back of your head telling you, "I need to reserve time to go back to question 1" or, "What if I could get the answer if I just spent 5 more minutes on it?"

    • If you're only allowed to work on one problem at a time, then the most optimal way to allocate your focus and energy is fully toward the problem at hand

by Laryn Qi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment