DeterminantFinder practice problem

Manipulation of 2 dimensional arrays is testable on the AP Computer Science A Exam. Multiple choice and free response questions are fair game. The DeterminantFinder practice problem is intended as practice with 2D arrays and with recursion.

The DeterminantFinder practice problem requires complex manipulation of 2D arrays of integers. It also requires coding a recursive method of significant complexity. DeterminantFinder is not intended to simulate an AP style free response question and should not be used as part of a practice test or for timing.

The AP CS Pictures Lab features 2D arrays.

You should complete the MatrixManipulator practice problem before attempting the DeterminantFinder practice problem.

DeterminantFinder instructions

A determinant is a mathematical value calculated from a square matrix. Wikipedia has a excellent article on determinants. There are also many other resources that explain what determinants are and how to find them. Review these first to gain an understanding of the mathematical concept.

Once you are capable of finding determinants on paper, download the DeterminantFinder skeleton code. Complete the documented (but unimplemented) methods of the DeterminantFinder class in the order below.

  1. Review the code for the (already implemented) method atLeastOneByOne.
  2. Complete the determinantDefined method.
  3. Complete the findTwoByTwoDeterminant method.
  4. Run DeterminantFinderTester.testTwoByTwoDeterminant and verify that the output matches the sample output below.
  5. Complete the removeRowAndColumn method.
  6. Complete the findDeterminant method.
  7. Run DeterminantFinderTester.testDeterminant and verify that the output matches the sample output below.

Sample output for DeterminantFinderTester

[10, 11]
[12, 13]
DeterminantFinder.findTwoByTwoDeterminant(matrix):
-2

[1, -2, 4, 0]
[7, 3, 0, 3]
[-1, 1, -4, 0]
[0, 3, 2, 1]
DeterminantFinder.findDeterminant(matrix):
-34

See the DeterminantFinder solution or review it with AP CS Tutor Brandon Horn.

Get AP CS Help

Leave a Reply