Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. (18 points) Understand the following algorithm. Simulate it mentally on the following four inputs, and state the outputs produced (value returned) in each case:
1. (18 points) 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: [o, 0, 0, 0, 0, 0, 0, 0,0, 0]: (d) A: -1, 2,-3,4,-5,6, 7,-8,9,-10] Algorithm Mystery (A:array1..n] of integer) sum, max: integer 1 sum=0 2 max = 0 3 for i = 1 to n for j = 1 to n sum = sum + A[j] if sum max then maxsum 9 return max
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started