Successors free response answer 2

Successors free response problem from the 2017 AP Computer Science A Exam.

Successors is #4 from the from the 2017 AP Computer Science A Free Response problems.

https://secure-media.collegeboard.org/ap/pdf/ap-computer-science-a-frq-2017.pdf

Part (a) – findPosition method

This is both my time constrained and considered approach.

public static Position findPosition(int num, int[][] intArr)
{
  for(int r = 0; r < intArr.length; r++)
    for(int c = 0; c < intArr[0].length; c++)
      if(intArr[r][c] == num)
        return new Position(r, c);

  return null;
}

Part (b) – getSuccessorArray method

This is both my time constrained and considered approach.

public static Position[][] getSuccessorArray(int[][] intArr)
{
  Position[][] successors = new Position[intArr.length][intArr[0].length];

  for(int r = 0; r < successors.length; r++)
    for(int c = 0; c < successors[0].length; c++)
      successors[r][c] = findPosition(intArr[r][c] + 1, intArr);

  return successors;
}

2017 AP CS Exam Free Response Solutions

Please note: The College Board has not yet released scoring guidelines for the 2017 AP CS A FR (as of this writing). Questions of the form, “How many points would I lose for ___?” can’t be answered.

2 thoughts on “Successors free response answer

  1. Reply Andre May 6,2017 7:37 am

    Would you be deducted a point if you wrote:

    successors[r][c] = intArr.findPosition(intArr[r][c] + 1, intArr);

    instead of:

    successors[r][c] = findPosition(intArr[r][c] + 1, intArr);

    ?

    • Reply Brandon Horn May 6,2017 10:16 am

      You would almost certainly lose a point for this. findPosition is a static method of the same class as getSuccessorArray. It is not a method of the array.

Leave a Reply