This covers a "software algorithm" from <https://stackoverflow.com/help/on-topic>

This is a from a lecture slide from class 
![enter image description here](https://i.stack.imgur.com/LD0Ld.png)

Here is the implementation of insertion sort that we used 

```
public static void insertionSort(int[] a) {
     for (int i = 1; i < a.length; i++) {
          int temp = a[i];
          int j = i;
          while (j >= 1 && a[j - 1] > temp) {
                a[j] = a[j - 1];
         }
         a[j] = temp;
     }
}

```

I would agree that the space complexity of local variables would be O(1) because its just the same local variables each time no matter the input size, i, j, and temp will each take up a block of memory. 

However I am confused about the space complexity of the array. <http://www.cs.northwestern.edu/academics/courses/311/html/space-complexity.html> had a similar example,

```
int sum(int a[], int n) {
    int r = 0;
    for (int i = 0; i < n; ++i) {
       r += a[i];
    }
    return r;
}

```

and said that this algorithm would require N units of memory for a, meaning its space complexity is O(N)?

Which is it? O(N) because the array would require N units of memory(dependent on input size) or O(1) because of pass by reference?