Complete the code to represent the space complexity of storing an array of size n.
Space complexity = O([1])The space needed to store an array grows linearly with the number of elements, so it is O(n).
Complete the code to express the space complexity of a recursive function that calls itself n times without extra storage.
Space complexity = O([1])Each recursive call adds a new layer to the call stack, so the space grows linearly with n, making it O(n).
Fix the error in the space complexity expression for a function that creates a 2D matrix of size n x n.
Space complexity = O([1])A 2D matrix with n rows and n columns stores n*n elements, so the space complexity is O(nΒ²).
Fill both blanks to complete the space complexity of a function that stores a list and a dictionary each with n elements.
Space complexity = O([1] + [2])
Both the list and dictionary store n elements, so their space complexities add up to O(n + n) which simplifies to O(n).
Fill all three blanks to complete the space complexity of a function that creates a list of size n, a set of size n, and a constant number of variables.
Space complexity = O([1] + [2] + [3])
The list and set each use O(n) space, and the constant variables use O(1). The total is O(n + n + 1), which simplifies to O(n).