Question: Q 1 ( Recursive Thinking ) : In many problems the most important part is how you combine the partial solutions ( from the recursive

Q1(Recursive Thinking):
In many problems the most important part is how you combine the partial solutions (from the recursive parts), to give the solution to the full problem. (Like Mergesort has to merge the two partial solutions).
Write a recursive function countTotals(int[] arr, int tot), which calls itself recursively once. The purpose of the function is count the number of times, the sum of two consecutive items, equals tot.
For instance, if tot =5, and the given array is [1,2,3,5,0,1,4,2], then the returned value should be: 3, because there are three places (2+3=5 ;5+0=5 ;1+4=5), where the sum of two consecutive items equals 5.
You should write the base case clearly. (The biggest part of this question is coming up the solution. The actual function is just one line of base case, and one line of recursion/return).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!