The SubarraySum algorithm below solves the problem of identifying how many ways
ID: 2247741 • Letter: T
Question
The SubarraySum algorithm below solves the problem of identifying how many ways there are to select a given total from an array. For example, in the array [1, 2, 4, 4, 7, 9, 10], there are 5 different ways to make a sum of 15: 1. [1, 4, 10] 2. [1, 4, 10] 3. [2, 4, 9] 4. [2, 4, 9] 5. [4, 4, 7] Note that the two fours are considered distinct, even though they have the same value. Answer the following questions about the SubarraySum algorithm. Input: data: array of integers with values 1-10 Input: n: size of data Input: t: positive integer Output: all of the distinct ways to select numbers from data that add up to t 1 Algorithm: SubarraySum 2 if n = 0 then 3 return 4 else 5 soln = 6 for i = 1 to n do 7 if data[i] = t then 8 Add {data[i]} to soln 9 else if data[i]Explanation / Answer
Answer:
1.
row 9 say information[i] < t,
it income t is forever better than information[i]
therefore, t - information[i] have to forever be optimistic.
2.
3.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.