Group Group Group Group Group Group Group Group Group

Space Complexity of passed Array

For chapter 2 Complexity.

func printSorted(_ array: [Int]) {
let sorted = array.sorted()
for element in sorted {
print(element)
}
}

You say that the space complexity is O(N) because of the new sorted array.

In Swift, arrays are passed by value. Should we exclude the space allocated for the “array” input variable when the function begins.

If we include the memory allocated to begin running the function, then it would be O(N*2) which is then O(N) anyways.

But should we always just ignore the space allocated for parameters passed by value?