Questions tagged [space-complexity]

The space complexity of an algorithm quantifies the amount of memory taken by an algorithm to run as a function of the size of the input to the problem. The space complexity of an algorithm is commonly expressed using big O notation, which suppresses multiplicative constants and lower order terms.

The space complexity of a program (for a given input) is the number of elementary objects that this program needs to store during its execution. This number is computed with respect to the size n of the input data.
Formally, for an algorithm T and an input x, DSPACE(T, x) denotes the number of cells used during the (deterministic) computation T(x). We will note DSPACE(T) = O(f (n)) if DSPACE(T, x) = O(f (n)) with n = |x | (length of x).

923 questions
0
votes
1 answer

How to calculate average growth daily in my storage?

I need to calculate the average daily growth of my company here in storage, but I have doubts, what would be the correct way? Sorry for using Google Translator. =) Space Used in Storage: f_date f_used 12/03/2013 2708100 13/03/2013 …
0
votes
1 answer

infix to prefix time and space complexity

I have been working on writing a Java program to convert from infix notation to prefix notation using an operand stack and an operator stack. I have implemented a working converter based on the pseudocode in the top answer here: conversion from…
0
votes
1 answer

Divide and Conquer algorithm for generating n-bit strings?

Can someone please tell how to generate n-bit strings(all possible combinations) i.e. counting bits form 0 to 2^n-1 using Divide and Conquer Approach. I was able to do this with the following algorithm, but the space complexity as well as time…
user1581106
0
votes
3 answers

Space complexity of C# sort on string lists

I'm implementing a program to sort large files that maybe don't fit in memory. All files will be sorted by lines so I'm thinking in use a List to do it. I already calculated how many lines I can have in memory to split the files in smaller files,…
Sheol
  • 164
  • 1
  • 3
  • 13
-1
votes
0 answers

Space De-Allocation After a Sum Operation

Suppose we have the function below: def foo(nums, k): add = sum(nums[:k]) return add In the function above, we temporarily create a sub-list of length k. We then calculate the sum of this sub-list, storing its value in add. My question is…
LateGameLank
  • 113
  • 5
-1
votes
1 answer

First Node of the Intersection between 2 Singly Linked Lists - Time & Space Complexity?

What is the time & space complexity of this method I wrote which returns the first node of the intersection between two singly linked lists (and if none found just null)? public Node getFirstNodeWhichIntersects(Node node1, Node node2) { Node…
-1
votes
2 answers

Space complexity of reassigning an array

What is the space complexity of the following Java code? public int[] foo(int[] x) { x = new int[x.length]; // Do stuff with x that does not require additional memory return x } Is it O(1) or O(N)? I've seen both answers. But I can't…
Frederik
  • 1,221
  • 2
  • 13
  • 22
-1
votes
2 answers

How is developed a strategy that allows you to stabilize any sorting algorithm for an Array with n Elements with "O(n) additional memory"?

For instance, Heap-Sort Algorithm is unstable or Quick Sort depends on the Implementation for stability. This stability must only be provided with O(n) additional memory, not the other strategies. I have tried this question for the whole day, but I…
-1
votes
1 answer

What is the Space complexity of initializing 2D array in a function that receive 2D array as input?

I was solving a leetcode problem , and wanted to find the space complexity[1] of a function that receives a 2D array of size nxn, and in the function I initialize a new 2D array of size (n-2)x(n-2) Here is the code /** * @param {number[][]} grid *…
Hasan S.
  • 17
  • 7
-1
votes
1 answer

Space complexity, Auxiliary space and Input space

Could you explain me this phrase concerning space complexity? It is composed of two different spaces; Auxiliary space and Input space.
-1
votes
1 answer

Does reduce accumulator takes space in memory?

I've following two different approaches and confused on which one is recommended and why in terms of readability and memory allocation. As per my understanding both are same in terms of space complexity both(two variables in first approach and…
Hemadri Dasari
  • 32,666
  • 37
  • 119
  • 162
-1
votes
1 answer

Space Complexity and Auxilary space for iterative code below>>>>

int fib(int n){ // let n = 4; int f[n+1]; // array length becomes 5 f[0] = 0; f[1] = 1; for(int i = 2 ; i <= n ; i++ ){ f[i] = f[i-1] + f[i-2]; } return f[n]; } Now, The Time Complexity of this program is coming…
-1
votes
2 answers

Why is allConstruct() here considered O(m) space complexity

Preface: This implementation was source from the following video: https://www.youtube.com/watch?v=oBt53YbR9Kk The question is regarding the space complexity of the following function: target: string wordBank: array of strings sample call:…
-1
votes
1 answer

What is the time and space complexity of this code? I'm very confused on this subject so I am asking

This is my code, it is a russian peasant multiplication algorithm. I find the time and space complexity very confusing so I needed some help. This is also for java language Thank you. int num1 = Integer.parseInt(jTextField1.getText()); int num2 =…
xKD
  • 5
  • 2
-1
votes
1 answer

I want to know this function's time complexity and space complexity

f(int n) { int array[n] if (n == 1) return; else { f(n/2); f(n/2); return; } } I know when f(n/2) is one, the time complexity is O(log n). but this function has two f(n/2). Does this function have a time complexity O((log n)^2)? and Is space…