Tips for the AP® Computer Science FRQs

By Mike
Share on facebook
Share on twitter
Share on linkedin

(Also check out my guide to studying computer science. I mention some additional important things there.)

The Free Response Question (FRQ) section of the AP Computer Science test is an interesting challenge that asks you for a mix of memorized knowledge and creative application of that knowledge. The problems will look familiar, but in their specifics they might not be aything you’ve seen before.

Here are some important ways to check if you’ve gotten off track. These are pretty simple and fast.

  • Read the question multiple times and make sure you understand the examples.
  • Work out your code execution in a table: see the guide to studying computer science
  • Check that you’ve declared your variables with the correct type: int, double, String, ArrayList, or array. Make sure you’ve got it right.
  • Check return types of functions – and make sure that you’re actually returning a value of that type. You must have at least one return statement somewhere.
  • The instance variables must be initialized and it’s usually best to do so in the constructor.
  • Go back to the problem statement at the end and make sure you’ve solved what it is actually asking.
  • Did I mention to read the question multiple times and make sure you understand the examples?
  • Test their given examples against your code.
  • Check that your code won’t generate an “INDEX OUT OF BOUNDS” exception.
  • Read the question again and make sure you understand the examples.
Read the question—more than once!

One of the best things you can do to improve your score is one of the easiest: just read the question really well! Read it more than once, take notes, and go back to it after you’ve written your code to check if it says what you thought.

Do one piece at a time and solve a simpler problem first.

This is really two related tips for designing complex things.

When the Wright brothers were designing their first aircraft, they needed many things to work together to acheive flight: the engine, the wings, and the controls, just to start. But they could approach these problems gradually by making simpler devices: a plane with wings only (no engine), an engine only, controls only, and so forth. They could work out the bugs one at a time before assembling all the parts into the final complex system.

It’s the same with coding on the AP test. The questions often require you to meet several requirements. The first part of this tip says that you should feel free to solve one piece at a time.

The second part of this tip is that you should solve a simpler problem first. During the AP test, try simplifying the question until you can find the answer easily. We’ll see more examples of this below.

Sometimes students feel that solving simpler problems doesn’t help because it’s too easy or it won’t teach them anything relevant to the real question. As we’ll see in the example below, this is not the case.

Tip: You don’t have to write your code in a linear order.

Because programs run in a linear order, from the topmost line of code moving toward the bottom, it’s tempting to write the code in this order. In fact, you may feel that you have to write in this order to really understand what’s going on.

But you can actually make it easier on yourself by writing portions of the code in any order that’s convenient. Start with the easiest section. That may be somewhere in the middle of the code. Or, start with the section that comes to mind first. Fill in the details in the order they naturally occur to you as you ponder the problem.

A sample problem: “The Name Problem”

You are given a string with multiple names separated by a colon. Example:

“Julie:Mike:Ann:Mark:Beth:David:Mary” 

The job is to write a function that finds the substring containing the fourth name. It will look like this:

public String findFourth(String input)
{
    [your code will go here]
}
Application to “The Name Problem”: Solve a simpler problem first

What can we do that’s simpler than solving this problem? Maybe we can write code that finds the first substring and leaves it at that.

// Precondition: there is at least one colon in 'input'.
public String findFourth(String input)
{
    // Find first substring.
    int colon1 = input.indexOf(":");
    return input.substring(0, colon1);
}

This code actually has a bug, but it’s not too complicated, right? You may feel that writing this accomplishes nothing. But hold on – you had to get at least three details right.

  • Remembering that indexOf is a method of a String, not a function.
  • Remembering that indexOf returns an int.
  • Remembering how substring works: it has two arguments and the second argument is one past the final character.

Make it easy on yourself and focus on details one at a time, instead of trying to recall them when you’re in the middle of something complex.

Another way to do one piece at a time: top-down design

In a program, the individual details have to be right and the overall organization of the program has to be right too.

Let’s call the details “low-level” and the organization of the program “high-level” (or “big picture”).

Another way to focus on one thing at a time is to start with the big picture and work toward the details: that’s called working “top-down”.

Example of working top-down with “The Name Problem”

You decide on the structure of your program first. Here is an example of a struture.

public String findFourth(String input)
{
    [int or bool or double] someStatusVariable;
    for (int i = 0; i < [something]; i++)
    {
       if ([some condition])
        {
            [do something with status variable]
            [maybe return]
        }
    }
}

I decided my program will have a loop and will operate on some kind of status variable within the loop. But there are details I’ve left to fill in later. Those words inside square brackets (‘[’ and ‘]’) are merely descriptions of what to fill in later, like fill-in-the-blanks.

Now we start to fill in the details. Because we’re finding the fourth name, perhaps we should loop four times. We have to determine what our status variable is and what the return value of the function is. I’ll go quickly here and say the following:

  • The return value will be the fourth name, so the return type is a String.
  • If there is no fourth name we’ll return an empty string.
  • Our status variable will be the next index we start searching at.

(It takes experience to make these choices; if this is confusing, just keep on working with me or in your class and in time you’ll get it.)

public String findFourth(String input)
{
    int lastIndex = 0;
    for (int i = 0; i < 4; i++)
    {
        int nextIndex = input.indexOf(":", lastIndex)
        if (nextIndex == -1)
        {
            return "";
        }
        nextIndex++;
    }
}

This program is actually not quite right (it causes an INDEX OUT OF BOUNDS exception in some cases) but it works well to illustrate the idea of filling in the details after choosing the high-level structure.

Copyright 2020, Mike Mossey
College Board® and AP® are trademarks registered by the College Board, which is not affiliated with, and does not endorse, this site.
PO Box 94611, Pasadena, CA, 91101
818-835-1127
mike@michaelmossey.com