Space complexity of list creation
<p>Could someone explain me what is the space complexity of beyond program, and why is it?</p>

<pre><code>def is_pal_per(str):

s = [i for i in str]
nums = [0] * 129

for i in s:
    nums[ord(i)] += 1

count = 0

for i in nums:
    if i != 0 and i / 2 == 0:
        count += 1

print count

if count &gt; 1:
    return False
else:
    return True
</code></pre>

<p>Actually, i'm interested in this lines of code. How does it influence on space complexity of above program?</p>

<pre><code>s = [i for i in str]
</code></pre>

<p><code>nums = [0] * 129</code></p>

<p>You have found the only two lines that allocate memory:</p>

<pre><code>s = [i for i in str]
nums = [0] * 129
</code></pre>

<p>The first grows linearly with <code>len(str)</code>, the second is a constant. Therefore, the space complexity of your function is O(N), N=length of <code>str</code>.</p>

python algorithm python-2.7 space-complexity