Search code examples
calgorithmcomplexity-theoryspace-complexity

Does return type affect on the space complexity?


When finding the space complexity of a given code sample does the return type of a function affects the space complexity? Assume that size of int is 2 bytes and size of float is 4 bytes. What is the space complexity for the following code sample?

int area(int height, float width) {
    return height * width;
}

Solution

  • Auxiliary Space is the extra space or temporary space used by an algorithm.

    Space Complexity of an algorithm is total space taken by the algorithm with respect to the input size. Space complexity includes both Auxiliary space and space used by input.

    So, the answer is yes. The return type is also taken into account while considering space complexity.