How to determine the space complexity of a code snippet (Big O) (javascript)
Go to solution
Solved by Mira Yurizaki,
1 hour ago, mrchow19910319 said:so whenever we try to determine the complexity of code, we only check what kind of value it returns.
Is this a correct understanding about big O??
For space complexity, no. It depends on the intermediate data the algorithm needs. Even if this function returns a single byte value, the Big-O for space complexity is still O(n) because it's generating a list of n elements as intermediate data. I would also argue the input data has an impact on the space complexity, but for the purposes of analyzing just the algorithm itself, only the intermediate data matters.
If we're talking about computational complexity, then this algorithm is actually larger than O(n), because of the inner loop.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now