44.3k views
2 votes
What is the space complexity of the algorithm?ArithmeticSeries(list, listSize) { i = 0 arithmeticSum = 0 while (i < listSize) { arithmeticSum = arithmeticSum + list[i] i = i + 1 } return arithmeticSum}

User Darasd
by
5.7k points

1 Answer

0 votes

Answer:

O(n) which is a linear space complexity

Step-by-step explanation:

Space complexity is the amount of memory space needed for a program code to be executed and return results. Space complexity depends on the input space and the auxiliary space used by the algorithm.

The list or array is an integer array of 'n' items, with the memory size 4*n, which is the memory size of an integer multiplied by the number of items in the list. The listSize, i, and arithmeticSum are all integers, the memory space is 4(3) = 12. The return statement passes the content of the arithmetic variable to another variable of space 4.

The total space complexity of the algorithm is "4n + 16" which is a linear space complexity.

User Techmag
by
5.9k points