Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4. 7 points) Computational problem solving: Understanding an algorithm and its s

ID: 662751 • Letter: 4

Question

4. 7 points) Computational problem solving: Understanding an algorithm and its strategy by simulating it on a specific input: Understand the following algorithm. Simulate it mentally on the following four inputs, and state the outputs produced (value returned) in each case: (a) A: [1, 2, 3, 4,5, 6, 7, 8, 9, 10] (b) A: [-1,-2,-3,-4, -5,-6,-7,-8,-9,-10], (c) A: [0, 0, 0, 0, 0, 0, 0, 0, 0, 01, (d) A: [-1, 2,-3, 4,-5, 6,7,-8,9,-10]. Algorithm-1 (A:array[1.n] of integer) sum, max: integer sum = 0 max = 0 for i 1 3 1 to n sum = 0 for j- i to m sum sumAil if sum > max then max = sum 9 return max Output when input is array (a) above: Output when input is array (b) above: Output when input is array (c) above Output when input is array (d) above What does the algorithm return when the input array contains all negative integers? What does the algorithm return when the input array contains all non-negative integers?

Explanation / Answer

1.
When input is array (a), output:
55

2.
When input is array (b), output:
0

3.
When input is array (c), output:
0

4.
When input is array (d), output:
10

5.
When the input array contains all negative integers, the algorithm returns 0.

6.
When the input array contains all positive integers, the algorithm returns the sum of all the elements of the arra.y

7.
When the input array contains negative, zero and positive integers, the algorithm returns the largest possible sum of any continuous sub array of the input array.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote