Misconception: When students trace through recursive code, they have trouble figuring out if operations are done before or after the recursive call.

  • In the following Java code from the 2009 AP CS A multiple choice, students may not be clear that the call mystery(x / 10) must resolve entirely before System.out.print(x % 10) can execute.

     
    //precondition: x <= 0
    public void mystery(int x) {
      if ((x / 10) != 0) {
        mystery(x / 10);

      }
      System.out.print(x % 10);

    }

  • Remember, the simpler you make your examples, the easier it will be for students to focus on understanding the recursion.

More about this tip

External Source

Leigh Ann Sudol-DeLyser’s notes from 2009 AP CS A exam.