title: How to calculate the space complexity of function?
body: <p>I understood the basic that if I have a function like this: </p>
  
  <pre><code>int sum(int x, int y, int z) {
    int r = x + y + z;
    return r;
  }
  </code></pre>
  
  <p>it requires 3 units of space for the parameters and 1 for the local variable, and this never changes, so this is <code>O(1)</code>.</p>
  
  <p>But what if I have a function like this: </p>
  
  <pre><code>void add(int a[], int b[], int c[], int n) {
      for (int i = 0; i &lt; n; ++i) {
          c[i] = a[i] + b[0]
      }
  }
  </code></pre>
  
  <p>Which requires N units for <code>a</code>, M units for <code>b</code> and L units for <code>c</code> and 1 unit for <code>i</code> and <code>n</code>. So it will need <code>N+M+L+1+1</code> amount of storage.</p>
  
  <p>So what will the big-O for space complexity here? The one which takes higher memory? 
  I.e. if N takes more higher momery than M and L (from much higher means suppose larger than <code>10**6</code>) - so is it safe to say space complexity is <code>O(N)</code> or not like we do for time complexity ?</p>
  
  <p>But if all three i.e a, b, c are not very much different </p>
  
  <p>Like this function</p>
  
  <pre><code>void multiply(int a[], int b[], int c[][], int n) { 
      for (int i = 0; i &lt; n; ++i) {
          for (int j = 0; j &lt; n; ++j) {
              c[i] = a[i] + b[j];
          }
      }
  }
  </code></pre>
  
  <p>Then what will be the space complexity? <code>O(N+M+L)</code>? Or still the biggest one? </p>