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

Javascript - Time and space complexity of splice and concat inside loop

I have a problem which requires a string to be transformed into another one by appending copies of its' initial value to itself. The problem allows to remove single characters at some places. Explanation let x = "abba"; // First string let y = "aba"…
user9410919
8
votes
1 answer

Python: Time and space complexity of creating size n^2 tuples

This is a question from a past-yr mid-term paper from my school. Attached below is a diagram to show how a robot will move, from the same paper. My concerns are stated in the orange portion. Basically, the robot moves forward and turns left…
Prashin Jeevaganth
  • 1,223
  • 1
  • 18
  • 42
8
votes
1 answer

Floyd–Rivest vs. Introselect algorithm performance

Google couldn't help me so here it goes: which of the two selection algorithms, FloydRivest algorithm and Introselect, has better performance. I'm assuming It's FloydRivest algorithm, but want to be 100% sure. Also, if there exist even better…
8
votes
2 answers

Why don't we consider stack frame sizes while calculation Space Complexity of recursive procedures?

Consider, the case of Merge Sort on an int Array containing n elements, we need an additional array of size n in order to perform merges.We discard the additional array in the end though.So the space complexity of Merge Sort comes out to be…
Aman Arora
  • 1,232
  • 1
  • 10
  • 26
7
votes
2 answers

A good sorting algorithm for mostly-sorted data that doesn't all fit into memory?

In case you are given: certain amount of data memory with size half of the data size part of the data is sorted you do not know the size of the sorted data. Which sorting algorithm would you choose? I am debating between insertion and quicksort. I…
FranXh
  • 4,481
  • 20
  • 59
  • 78
7
votes
1 answer

What is the Computational Complexity of Mathematica's CylindricalDecomposition

Mathematica' CylindricalDecomposition implements an algorithm known as Cylindrical Algebraic Decomposition. Wolfram MathWorld's article on Cylindrical Algebraic Decomposition says that this algorithm "becomes computationally infeasible for…
7
votes
5 answers

Time and Space complexity for calculating many fish are alive?

I was working on a Codility problem: You are given two non-empty zero-indexed arrays A and B consisting of N integers. Arrays A and B represent N voracious fish in a river, ordered downstream along the flow of the river. The fish are numbered…
Nicky
  • 1,025
  • 3
  • 15
  • 29
7
votes
6 answers

Bloom Filter Implementation

Using Bloom filter, we will be getting space optimization. The cassandra framework also has an implementation of Bloom Filter. But in detail, how is this space optimization achieved?
UVM
  • 9,776
  • 6
  • 41
  • 66
7
votes
2 answers

What is the time complexity and space complexity of array[::-1]

When reverse a list in Python, I usually use the array[::-1] for reversing and I know that a more common way might swap from two sides of the list. But I'm not sure the difference between these two solutions such as time complexity and space…
JoshuaW1990
  • 142
  • 1
  • 8
7
votes
2 answers

Out of core connected components algorithms

I have 4,000,000,000 (four billion) edges for an undirected graph. They are represented in a large text file as pairs of node ids. I would like to compute the connected components of this graph. Unfortunately, once you load in the node ids with the…
Simd
  • 19,447
  • 42
  • 136
  • 271
7
votes
1 answer

Hamming numbers for O(N) speed and O(1) memory

Disclaimer: there are many questions about it, but I didn't find any with requirement of constant memory. Hamming numbers is a numbers 2^i*3^j*5^k, where i, j, k are natural numbers. Is there a possibility to generate Nth Hamming number with O(N)…
vladon
  • 8,158
  • 2
  • 47
  • 91
7
votes
1 answer

Why does Unix block size increase with bigger memory size?

I am profiling binary data which has increasing Unix block size (one got from stat > Blocks) when the number of events are increased as in the following figure but the byte distance between events stay constant I have noticed some changes in other…
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
7
votes
3 answers

What is time and space complexity of Dictionary?

Let's assume I have data of size N (i.e.N elements) and the dictionary was created with capacity N. What is the complexity of: space -- of entire dictionary time -- adding entry to dictionary MS revealed only that entry retrieval is close to…
greenoldman
  • 16,895
  • 26
  • 119
  • 185
7
votes
2 answers

What is the best in place sorting algorithm to sort a singly linked list

I've been reading on in place sorting algorithm to sort linked lists. As per Wikipedia Merge sort is often the best choice for sorting a linked list: in this situation it is relatively easy to implement a merge sort in such a way that it requires…
uyetch
  • 2,150
  • 3
  • 28
  • 33
7
votes
2 answers

Real world examples to decide which sorting algorithm works best

I am risking this question being closed before i get an answer, but i really do want to know the answer. So here goes. I am currently trying to learn algorithms, and I am beginning to understand it as such but cannot relate to it. I understand Time…
Amey
  • 8,470
  • 9
  • 44
  • 63