Ahaan

FRQ 4 Homework 2017

FRQ 4 Homework 2017

Proof of Completion and Running on Open Coding Society Code Runner

Key Takeaways

  1. Nested Loop Traversal of 2D Arrays: In findPosition, using nested loops (outer for rows, inner for columns) is the standard pattern for searching through every element in a 2D array.

  2. Returning a Position Object: When the target value is found at intArr[r][c], returning new Position(r, c) encapsulates the row and column into a single object — a common pattern for representing coordinates.

  3. Returning null After Exhaustive Search: Placing return null outside both loops ensures it only executes after every element has been checked, correctly signaling that the value was not found.

  4. Successor = Current Value + 1: In getSuccessorArray, the key insight is that the successor of intArr[r][c] is intArr[r][c] + 1. Passing this value to findPosition locates where the next consecutive integer lives in the array.

  5. Delegating to a Helper Method: getSuccessorArray calls findPosition for each element rather than re-implementing the search logic. This demonstrates method decomposition — writing one method that searches and another that coordinates the overall task.

Area of Improvement

My main struggle was correctly creating the result 2D array with matching dimensions. I initially used new Position[intArr.length][intArr[0].length] for all rows, but had to remember to initialize each row individually with result[r] = new Position[intArr[r].length] to handle potentially jagged arrays. I also initially forgot to pass intArr[r][c] + 1 (the successor value) to findPosition and instead passed intArr[r][c] itself, which returned the position of the current element rather than its successor.

Scroll to top