Tags
 IOS SQL HTML C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6

# What is the space complexity of my python function?

By : Amir Pasha
Date : October 16 2020, 03:08 PM
wish help you to fix your issue a is just a variable, and here you assign a with integer value, for this point, the space complexity is O(1).
But I think the key to measure is in for i in range(n) statement.
code :

Share :

## What is the Time Complexity, Space complexity and Algorithm for strstr() function in C++?

By : joedeloy
Date : March 29 2020, 07:55 AM
hope this fix your issue I was curious about the cost of using the default, old fashioned strstr() function in C++. What is its Time and Space complexity? Which algorithm does it use? We have other algorithms with below Worst Case Time and Space complexity : Let n = length of string, m = length of pattern , In the C standard it just says, in §7.24.5.7:
Synopsis
code :
`````` #include <string.h>
char *strstr(const char *s1, const char *s2);
``````

## Which function is faster in terms of time complexity/space python

By : Daquan Wright
Date : March 29 2020, 07:55 AM
Any of those help First, your solution is wrong, but we'll get into why later.
Technically your solution is O(n), but not in a good way.
code :
``````idx = 0
max = 0
min = 9999999
for i, item in enumerate(list):
if item > max:
max = item
if item < min:
min = item
idx = i
``````
``````def get_max_profit(list):
"""Use list[0] to store min
and list[1] to store max
"""
# Swap the first two if they are out of order
if list[0] > list[1]:
list[0], list[1] = list[1], list[0]
# Find min and max in remainder of list
for price in list[2:]:
if price < list[0]:
list[0] = price
if price > list[1]:
list[1] = price
# Return the difference
return list[1] - list[0]
``````

## Space Complexity (Python)

By : Beni Korba
Date : March 29 2020, 07:55 AM
should help you out It depends on your python version. If you are using python 2, it creates the list for range function. Respectively, list needs O(n) memory complexity. Otherwise, if you are using python 3, it creates the generator.
UPDATE: As Vineeth said range is not an iterator. Sorry for misleading.

## Space complexity of recursive function (Time & Space)

By : Ameya05
Date : March 29 2020, 07:55 AM
may help you . Yes, the time complexity is indeed O(2 ^ n).
The recurrence relation for time complexity is: T(n) = 2 * T(n - 3)

## Space complexity of split() function in python

By : user3318556
Date : March 29 2020, 07:55 AM
it fixes the issue In python strings are immutable objects, which means that they cannot change at all "in-place". All actions on them essentially take up new memory space, and hopefully, the old unused ones are deleted by python's garbage collecting process (if there are no more references to those objects). One method to see it for yourself is this:
code :
``````>>> a = 'hello world'
>>> id(a)
1838856511920
>>> b = a
>>> id(b)
1838856511920
>>> a += '!'
>>> id(a)
1838856512944
>>> id(b)
1838856511920
``````
``````>>> sentence = "hello world"
>>> id(sentence)
1838856521584
>>> sentence = sentence.split()
>>> id(sentence)
1838853280840
``````
``````>>> import sys
>>> sentence = "hello world"
>>> sys.getsizeof(sentence)
60
>>> sentence = sentence.split()
>>> sys.getsizeof(sentence)
160
``````
 Privacy Policy - Terms - Contact Us © soohba.com