Skip to content

Commit 1bbfacc

Browse files
authored
Merge pull request #173 from RunestoneInteractive/fix-7.2
Improve section 7.2
2 parents 11f011d + cbaee73 commit 1bbfacc

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

source/ch7_recursion.ptx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ main()
233233
</p>
234234
<program xml:id="array-sum-java-with-helper" interactive="activecode" language="java">
235235
<code>
236+
import java.util.Arrays;
237+
236238
public class ArrayProcessor {
237239
public static int sumArray(int[] arr) {
238240
// Handle empty array
@@ -263,11 +265,11 @@ public class ArrayProcessor {
263265
</program>
264266

265267
<p>
266-
Compare these improved versions with the earlier problematic ones. Notice how much cleaner the method calls become: <c>processor.sum_array(numbers)</c> in Python and <c>sumArray(numbers)</c> in Java. Users no longer need to worry about providing the correct starting index or understanding the internal mechanics of the recursion. The helper method pattern creates a clear separation between what users need to know (just pass an array) and the implementation details (tracking the index through recursion).
268+
Compare these improved versions with the earlier problematic ones. Notice how much cleaner the method calls become: <c>processor.sum_array(numbers)</c> in Python and <c>sumArray(numbers)</c> in Java. Users no longer need to worry about providing a starting index or understanding the internal mechanics of the recursion. The helper method pattern creates a clear separation between what users need to know (just pass an array) and the implementation details (tracking the index through recursion).
267269
</p>
268270

269271
<p>
270-
This helper method pattern is essential when your recursive algorithm needs to track additional state (like array positions, accumulated values, or depth counters) that the original caller shouldn't need to provide or care about. It's a fundamental pattern and technique you'll likely use frequently in recursive problem solving.
272+
This helper method pattern is invaluable when your recursive algorithm needs to track additional state details (like array positions, accumulated values, or depth counters) that the original caller shouldn't need to know about or care about. It's a fundamental pattern and technique you'll likely use frequently in recursive problem solving.
271273
</p>
272274
</section>
273275

0 commit comments

Comments
 (0)