Static assumptions - computer science

66 Views Asked by At

Specify all conditions, assumptions and limitations for the following code that needs to compute an average value of different numbers in an interval $[1,10000]$. Conditions, assumptions and limitations must be written in mathematical language.

enter image description here

Could someone explain what are conditions, assumptions and limitations and specify them in mathematical language?

1

There are 1 best solutions below

0
On

The computer code you posted has limitations in terms of the size of the programming language types such as integer and double. One issue would be that the total of all the numbers must fit into the range of the double. Another would be that the maximum number of values in the array must be less than the indexing type used (int). The size of the array must be at least 1, since you can't make an average of zero numbers. I think there might be a problem when dealing with very large datasets of very large numbers and very small integers, in that the double used to store the intermediate result only has a finite precision, so you might loose the contributions of the smaller numbers to the average.

( there seems to be a bug in the code where the loop starts at 1, so if you had a single value in the array arr, the code would not correctly compute the average ).

I have no idea if this is the type of answer your professor is looking for, only you have your lecture notes, so it should be covered in class - otherwise see the professor or TA for help.