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
-2
votes
1 answer

Calculating time and space asymptotic complexity of a function

I've just started learning time and space complexity and I'm having trouble in calculating it for this program. void f(int n){ int a[4] = {1, 1, 1, 1}; for(int k = 0; k < n; k++){ a[k % 4] *=3; } int** ptr = (int…
-2
votes
1 answer

Time Complexity And Space Complexity Of This Code?

What is the Time & Space Complexity of this code ? Here,is the code for moving all the negative elements of any array to the end of the array while maintaining the order of all non-negative elements as well as negative elements - as, Input :…
-2
votes
1 answer

what is the time and space complexity of this implementation in JavaScript of quick sort algorithm?

I'm wondering what is the time and space complexity of this quick sort implementation in JavaScript. Does it have more than the ideal time and space complexity of quick sort or is it same? (Ideal quick sort has TC O(n^2) and SC O(log n) in worst…
-2
votes
1 answer

Time and space complexity - for loop inside of while loop

What is the time & complexity of the code below? function SortFunction (entries): sorted_entries = {} while entries is not empty: smallest entry = entries [0] foreach entry in entries: if (entry…
noob123
  • 59
  • 1
  • 6
-2
votes
1 answer

Reduce the space complexity of the following fibonacci algorithm

Reduce the space complexity of the following fibonacci algorithm. I need help with this. I can't think of any way to do this. Any help would be much appreciated. public static long fibonacci (int n){ long[] f = new long[n+1]; f[0] = 0; …
-2
votes
1 answer

What is the Time and Space Complexity of this code

What is the Time and Space complexity of this code (Find Uniques and duplicates)? arr = [1,1,1,2,4,2,5] a = [] d = [] for i in arr: if i not in a: a.append(i) elif i in a: d.append(i) print(a) print(d)
-2
votes
2 answers

Time and Space complexity of a Balanced Binary Search Tree

What is computational complexity(time and space complexity) of building a Balanced Binary Search Tree?
-2
votes
1 answer

What is the Space Complexity of this given code snippet?

The time complexity is O(2^N). How to derive the space complexity for this code? int f(int n){ if(n <= 1){ return 1; } return f(n-1) + f(n-1); }
aji13
  • 75
  • 8
-2
votes
1 answer

Time and Space Complexity of given algorithm

I am having an algorithm and wanted to find it time and space complexity. Algorithm is Algorithm for Scheduling INPUT:P1,P2, PN // N processes do Sort processes in ascending according to their burst time TQ = median of burst time of…
-2
votes
2 answers

How to calculate complexity of this program? Can there be any other solution with less complexity?

Question link: https://leetcode.com/contest/biweekly-contest-1/problems/campus-bikes-ii/ I want to calculate the complexity of this program, I think the complexity of my code is O(b^w) where b is the size of total bikes and w is the size of total…
Vijay Sharma
  • 342
  • 4
  • 15
-2
votes
1 answer

What is the efficient algorithm / way to find intersection between 2 array lists. ( I am using java 8 )

I have 2 array lists which contains a custom object Stock. public class Stock{ private String companyName; private double stockPrice; // getters and setters } List1 contains Stock objects . List2 also contains stock objects. List 1…
CodeMaster
  • 171
  • 15
-2
votes
1 answer

Memory usage of a function in Python 3.x

Are there any specific Python libraries to quantify practically both space (memory consumption) and time complexity (time consumption) of a specific function in Python 3.x, by providing avg/max/min stats?
-2
votes
2 answers

Space complexity of adding Java Strings char by char

When building a Java String char by char through a loop through "addition", it can be observed that the time complexity of performing this operation is poor: it is of quadratic O(n^2) time. However, I am wondering if the space complexity of "adding"…
-2
votes
1 answer

Space and time complexity of lisp functions

Here are two lisp's functions (defun fact (x &optional (acc 1)) (if (zerop x) acc (fatt (- 1 x) (* x acc)))) (defun fatt (x) (if (zerop x) 1 (* x (fatt (- x 1))))) How can I find space and time complexity of this functions?
-2
votes
2 answers

Array Space Complexity

I have a question that : I have an array "S" which has n objects in it. also each object has m fields. I want to save some of them in the another array like "Q" . I want to know that the space complexity of this easy method is O(|Q|)?
user472221
  • 3,014
  • 11
  • 35
  • 42