0% found this document useful (0 votes)
19 views13 pages

2017 AP Computer Science A Scoring Guide

Uploaded by

lcvolstorf
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views13 pages

2017 AP Computer Science A Scoring Guide

Uploaded by

lcvolstorf
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

2017

AP Computer Science A
Sample Student Responses
and Scoring Commentary

Inside:

• Free Response Question 4


• Scoring Guideline
• Student Samples
• Scoring Commentary

© 2017 The College Board. College Board, Advanced Placement Program, AP, AP Central, and the acorn logo
are registered trademarks of the College Board. Visit the College Board on the Web: [Link].
AP Central is the official online home for the AP Program: [Link]
AP® COMPUTER SCIENCE A
2017 GENERAL SCORING GUIDELINES

Apply the question assessment rubric first, which always takes precedence. Penalty points can only be
deducted in a part of the question that has earned credit via the question rubric. No part of a question
(a, b, c) may have a negative point total. A given penalty can be assessed only once for a question, even if
it occurs multiple times or in multiple parts of that question. A maximum of 3 penalty points may be
assessed per question.

1-Point Penalty
v) Array/collection access confusion ([] get)
w) Extraneous code that causes side-effect (e.g., printing to output, incorrect precondition check)
x) Local variables used but none declared
y) Destruction of persistent data (e.g., changing value referenced by parameter)
z) Void method or constructor that returns a value

No Penalty
o Extraneous code with no side-effect (e.g., valid precondition check, no-op)
o Spelling/case discrepancies where there is no ambiguity*
o Local variable not declared provided other variables are declared in some part
o private or public qualifier on a local variable
o Missing public qualifier on class or constructor header
o Keyword used as an identifier
o Common mathematical symbols used for operators (× • ÷ < > <> ≠)
o [] vs. () vs. <>
o = instead of == and vice versa
o length/size confusion for array, String, List, or ArrayList; with or without ( )
o Extraneous [] when referencing entire array
o [i,j] instead of [i][j]
o Extraneous size in array declaration, e.g., int[size] nums = new int[size];
o Missing ; where structure clearly conveys intent
o Missing { } where indentation clearly conveys intent
o Missing ( ) on parameter-less method or constructor invocations
o Missing ( ) around if or while conditions

*Spelling and case discrepancies for identifiers fall under the “No Penalty” category only if the correction
can be un am biguousl y inferred from context, for example, “ArayList” instead of “ArrayList.” As a
counterexample, note that if the code declares “int G=99, g=0;”, then uses “while (G < 10)”
instead of “while (g < 10)”, the context does n ot allow for the reader to assume the use of the lower
case variable.

© 2017 The College Board.


Visit the College Board on the Web: [Link].
AP® COMPUTER SCIENCE A
2017 SCORING GUIDELINES

Question 4: Successor Array

Part (a) findPosition 5 points


Intent: Find the position of a given integer in a 2D integer array

+1 Accesses all necessary elements of intArr (no bounds errors)

+1 Identifies intArr element equal to num (in context of an intArr traversal)

+1 Constructs Position object with same row and column as identified intArr element

+1 Selects constructed object when intArr element identified; null when not

+1 Returns selected value

Part (b) getSuccessorArray 4 points


Intent: Create a successor array based on a 2D integer array

+1 Creates 2D array of Position objects with same dimensions as intArr

+1 Assigns a value to a location in 2D successor array using a valid call to findPosition

+1 Determines the successor Position of an intArr element accessed by row and column
(in context of intArr traversal)

+1 Assigns all necessary locations in successor array with corresponding position object or null
(no bounds errors)

Question-Specific Penalties

-1 (s) Uses confused identifier Arr

-1 (t) Uses intArr[].length as the number of columns

-1 (u) Uses non-existent accessor methods from Position

© 2017 The College Board.


Visit the College Board on the Web: [Link].
AP® COMPUTER SCIENCE A
2017 SCORING GUIDELINES

Question 4: Scoring Notes

Part (a) findPosition 5 points


Points Rubric Criteria Responses earn the point if they ... Responses will not earn the point if they ...
Accesses all • use if (...) return;
necessary else return null; inside loop
+1 elements of • confuse row and column bounds
intArr (no
bounds errors) • fail to traverse intArr
Identifies intArr • use .equals instead of ==
element equal to
+1 num (in context of
an intArr
traversal)
Constructs • omit keyword new
Position object • use (r,c) instead of
with same row and Position(r,c)
+1 column as
identified intArr
element
Selects constructed • use "null" instead of null • use if (...) return;
object when • construct a String object using else return null; inside loop
+1 intArr element row and column indices • use (r,c) instead of
identified; null
Position(r,c)
when not
Returns selected
+1 value
Part (b) getSuccessorArray 4 points
Points Rubric Criteria Responses earn the point if they ... Responses will not earn the point if they ...
Creates 2D array of • omit keyword new
Position objects
+1 with same
dimensions as
intArr
Assigns a value to a • call • reimplement the code from
location in 2D [Link](…) findPosition
+1 successor array • call findPosition with a single
using a valid call to argument
findPosition • call [Link](…)
Determines the • reimplement the code from • call findPosition using an
successor findPosition integer that is not identified with a
Position of an location in intArr
intArr element
+1 • call findPosition with a single
accessed by row
and column (in argument
context of intArr
traversal)
Assigns all • use SuccessorArray dimensions • reimplement the code from
necessary locations correctly, even if SuccessorArray findPosition but mishandle the
in successor array was not initialized properly null case.
+1 with corresponding
• fail to traverse intArr
position object or
• only assign non-null entries to
null (no bounds
SuccessorArray
errors)

Return is not assessed in Part (b).

© 2017 The College Board.


Visit the College Board on the Web: [Link].
AP® COMPUTER SCIENCE A
2017 SCORING GUIDELINES

Question 4: Successor Array

Part (a)

public static Position findPosition(int num, int[][] intArr)


{
for (int row=0; row < [Link]; row++)
{
for (int col=0; col < intArr[0].length; col++)
{
if (intArr[row][col] == num)
{
return new Position(row, col);
}
}
}
return null;
}

Part (b)

public static Position[][] getSuccessorArray(int[][] intArr)


{
Position[][] newArr = new Position[[Link]][intArr[0].length];

for (int row=0; row < [Link]; row++)


{
for (int col=0; col < intArr[0].length; col++)
{
newArr[row][col] = findPosition(intArr[row][col]+1, intArr);
}
}
return newArr;
}

These canonical solutions serve an expository role, depicting general approaches to solution. Each reflects only one instance from the
infinite set of valid solutions. The solutions are presented in a coding style chosen to enhance readability and facilitate understanding.

© 2017 The College Board.


Visit the College Board on the Web: [Link].
© 2017 The College Board.
Visit the College Board on the Web: [Link].
© 2017 The College Board.
Visit the College Board on the Web: [Link].
© 2017 The College Board.
Visit the College Board on the Web: [Link].
© 2017 The College Board.
Visit the College Board on the Web: [Link].
© 2017 The College Board.
Visit the College Board on the Web: [Link].
© 2017 The College Board.
Visit the College Board on the Web: [Link].
AP® COMPUTER SCIENCE A
2017 SCORING COMMENTARY

Question 4

Overview

This question involved reasoning about two-dimensional (2D) arrays of integers and objects. The students
were expected to write two static methods of an enclosing Successors class. A provided Position
class was used to represent an integer’s location (row and column) in a 2D array.

In part (a) students were asked to implement a static method with two parameters, an integer value, and a
2D array of integers. They were expected to search the given array for the given value. If found, students
were expected to create and return a new Position object representing the value’s location in the array.
Otherwise they were expected to return null.

In part (b) students were asked to implement a static method with a 2D array of integers parameter. They
were expected to create a 2D array of Position references with the same dimensions as the given array.
Then they were to use the method they implemented in part (a) to find the position of the successor (integer
one greater) for each integer in the given array. They then assigned this successor position to the
corresponding element in the new array. Finally, they returned the new array.

In writing the required methods, correct responses demonstrated the ability to search a 2D array, create new
Position and 2D array objects, return objects and null, use parameters and local variables, implement
and invoke static methods, and demonstrate the principle of code reuse by utilizing a previously
implemented method.

Sample: 4A
Score: 8

In part (a) a boolean variable tF is declared and initialized to false. Then all intArr elements are
compared with num. If an equal element is found, a Position reference p is declared and a
Position object with the corresponding row and column is constructed and assigned to p. Also tF is
set to true. After the loops !tF is evaluated to determine if no equal element was found, in which case
null is returned. Otherwise p is returned. This logic earned points 1–4. However, because p is declared
inside the if statement, it is out of scope (inaccessible) in the return statement. Therefore point 5 was
not earned. Part (a) earned 4 points.

In part (b) the 2D array variable pos is created and assigned a correctly sized 2D array of Position
references, which earned point 1. Nested loops are used to iterate over every element of intArr. In the
nested loop body, the findPosition method is invoked to obtain the Position object representing
the position of the successor of intArr[r][c]. If an intArr element does not have a successor,
findPosition returns null. These values are correctly assigned to the corresponding elements in the
pos 2D array and points 2-4 are earned. Part (b) earned 4 points.

Sample: 4B
Score: 4

In part (a) the extraneous parentheses after each length were not penalized, but the second for loop
header has intArr[].length, which does not correctly retrieve the number of columns in intArr,
and i++ instead of j++. Therefore not every intArr element is iterated, so point 1 was not earned. An
intArr element is compared for equality with num in the context of an intArr traversal, so point 2
was earned. No object is constructed, so neither point 3 nor point 4 were earned. However, the selected value
of (2,1) is returned, so point 5 was earned. Part (a) earned 2 points.

© 2017 The College Board.


Visit the College Board on the Web: [Link].
AP® COMPUTER SCIENCE A
2017 SCORING COMMENTARY

Question 4 (continued)

In part (b) point 1 was not earned for several reasons, including the int[][] type (Java allows type
name[][]), new Array, and the incorrect number of columns. The invocation of findPosition in the
context of the intArr traversal earned point 3. (Extraneous square brackets when referring to an entire
array are not penalized.) Even though point 1 was not earned, the response attempts to declare Position
as a 2D successor array. Therefore the assignment of the returned Position to Position[i][j]
earned point 2. The loop bounds error for j prevented point 4 from being earned. Part (b) earned 2 points.

Sample: 4C
Score: 1

In part (a) the nested loop body consists of an if-else statement that always returns during the first
iteration. As a result, neither point 1 nor point 4 were earned. Furthermore, both loop bounds are incorrect,
and num is compared with int[i][j] instead of intArray[i][j]. These errors result in point 1
and point 2 not being earned. Additionally, num is a primitive and primitives don’t have methods, so
[Link](…) also resulted in point 2 not being earned. No Position object is created, so point 3
was not earned. However, return (i,j) earned point 5. Part (a) earned 1 point.

In part (b) no 2D array of Position objects is created, so point 1 was not earned. Because intArr is not
traversed, findPosition is not called, and no successor positions are determined, points 2–4 were not
earned. Part (b) earned no points.

© 2017 The College Board.


Visit the College Board on the Web: [Link].

Common questions

Powered by AI

The handling of array boundaries in the provided code samples focuses on avoiding out-of-bounds errors. In Source 3, both nested for loops in the method findPosition properly check their conditions using row < intArr.length and col < intArr[0].length to ensure they do not exceed the bounds of the 2D array. The sample also ensures that all necessary elements of intArr are accessed without bounds errors . On the other hand, errors in code samples like in Source 4 result from incorrectly setting loop bounds, such as using intArr[].length as the number of columns, which does not correctly retrieve column numbers . This difference in handling array boundaries highlights the importance of accurate dimension checking to avoid accessing elements outside of allocated memory, which could lead to runtime errors.

The scoring guidelines demonstrate the importance of correctly handling method inputs and outputs through practices like matching parameters and return types to method requirements. For instance, the findPosition method must take specific input types (integer and 2D array) and return a Position object or null, addressing both valid and invalid cases . Effective management of method inputs and returning appropriate outputs like Position objects ensure that the method interfaces align with their expected tasks and improve code robustness and clarity. Adherence to input and output specifications is critical in avoiding errors. This practice is also illustrated by penalties for inappropriate types or failing to initialize necessary objects before returning . Correct input management and clear output help in maintaining dependable interfaces across methods.

Traversing a 2D array is crucial for solving Question 4 effectively, as both the findPosition and getSuccessorArray methods require accessing each element of the array methodically. The traversal is achieved through nested loops that iterate over rows and columns, ensuring that every element is examined. This structured traversal is essential for accurately identifying elements that match specific criteria, such as checking for an integer equal to a given number or its successor . The significance of understanding 2D array traversal lies in its frequent necessity for accessing multi-dimensional data structures in computing. It forms the basis for implementing the logic required to manipulate arrays for various tasks, including searching and updating elements. Properly implementing such traversal ensures that every element is adequately processed, avoiding errors such as skipping elements or encountering null references .

Implementing the Successor Array methods necessitates a robust understanding of several key concepts in computer science, including 2D array traversal, object-oriented programming, and method interaction. The task requires students to employ nested iterations correctly to traverse the 2D array, ensuring all elements are considered, which involves understanding row-major order access patterns . Additionally, conceptualizing the implementation requires designing a method interface that correctly handles exceptions like missing elements (using null), constructing appropriate objects on-the-fly, and utilizing existing methods to build new functionalities (code reuse). Achieving these implementations also depends on understanding object references, method invocation, and control flow decisions (e.g., handling conditions that return different types of results). A strong grasp of these concepts ensures the construction of a coherent solution aligning with logical expectations and error handling .

Variable scope and declaration significantly impact the correctness of solutions to Question 4. For example, one sample incorrectly places the declaration of a Position reference within an if-statement, resulting in the object being inaccessible outside that statement where it needs to be returned . Proper variable scope ensures that variables are accessible where needed, and their lifetime meets the needs of the solution. Declaring variables at the correct scope allows for their use across methods where necessary, especially in cases of object creation returned by methods like findPosition . The implications of mishandling scope include runtime errors or unexpected behavior if variables are used before being defined or when they go out of scope prematurely, leading to failure in earning certain points or penalties in proper array and object handling . Understanding and correctly applying variable scope is crucial for ensuring program reliability and functionality.

The use of null is central to handling cases where a search within an array does not yield a result. In the findPosition method, returning null signifies that the searched integer does not exist within the array, providing a clear indication of absence . This explicit use of null serves as an important logical branch, allowing the getSuccessorArray method to handle cases where no successor exists by appropriately placing a null in the 2D successor array . Handling null correctly is vital for ensuring that each element's status is explicitly captured, which aids in differentiating between valid positions and voids. Furthermore, returning null avoids unnecessary errors when non-matching elements are involved, ensuring the logic remains robust and predictable. As such, null acts as a sentinel value, guiding control flow and preventing unintended operations on non-existent elements .

The Position class serves as a pivotal part of the solution by encapsulating the row and column indices of an element in the 2D array into a single object. Its role is most evident in methods such as findPosition and getSuccessorArray, where Position objects are created and returned to indicate the location of specific elements, such as the position of an integer or its successor. This encapsulation not only improves code readability but also enhances its modularity and maintainability, making it easier to work with positional data as single objects rather than raw indices . The construction of the Position object within the findPosition method involves using the keyword new, which constructs a Position object when a match is found. This use of object-oriented principles simplifies interactions with the 2D array and ensures that rows and columns are managed in a structured manner, ultimately impacting the solution by permitting the elegant handling of positions within the solution space .

The primary inefficiency in the provided solutions is the repeated full traversal of the intArr in both the findPosition and getSuccessorArray methods, especially when multiple elements share a successor position or non-existing successors are common. This can result in unnecessary computational overhead. An improvement could involve caching the results of findPosition for already computed successors to avoid recalculating their positions repeatedly. This could be achieved with a Map where keys are integers from intArr, and values are their corresponding Position objects. By populating this Map during the first traversal, subsequent lookups for successors would be reduced to constant-time operations, thereby reducing the overall time complexity from potential O(n^3) to O(n^2) in the worst case for getSuccessorArray processing . Implementing memoization strategies would optimize the code for large datasets by eliminating redundant searches and unnecessary iterations .

The document addresses common coding errors, such as array index errors, incorrect method signatures, and syntax errors, through explicit rubric points and penalties. Penalties are assessed based on a detailed rubric, where specific coding issues are aligned with penalty points. For instance, array index errors or confusion between rows and columns can lead to the failure of earning specific rubric points, such as accessing necessary elements of an array without bounds errors . Additionally, confusion between length and size methods, or improper method usage, also results in penalties. A maximum of three penalty points can be deducted per question, ensuring a structured approach to penalizing common coding errors . The penalties are not cumulative across parts of a question, reflecting an attempt to fairly evaluate student understanding while allowing for single-error forgiveness.

Code reuse in the AP Computer Science A 2017 Question 4 is prominently demonstrated by the way the getSuccessorArray method leverages the already implemented findPosition method. This approach ensures that once the logic for finding a position is correctly implemented and debugged in findPosition, it can be reused whenever a position needs to be located, reducing redundancy and potential errors. The getSuccessorArray method iteratively uses findPosition to determine the successor position for each element in the array, thus showcasing the DRY (Don't Repeat Yourself) principle . This not only consolidates the logic into a single method but also simplifies maintenance and testing.

You might also like