Questions tagged [space-analysis]
45 questions
32
votes
1 answer
Does space complexity analysis usually include output space?
Since most examples of complexity analysis I've seen involve functions that return either nothing (e.g. in-place sort) or a single value (e.g. computation, lookup), I haven't been able to figure this out just by reading examples.
If a function…
Kevin Kibler
- 423
- 1
- 4
- 7
12
votes
3 answers
Why is DFS considered to have $O(bm)$ space complexity?
According to these notes, DFS is considered to have $O(bm)$ space complexity, where $b$ is the branching factor of the tree and $m$ is the maximum length of any path in the state space.
The same is said in this Wikibook page on Uninformed…
user20691
11
votes
5 answers
Does an algorithm's space complexity include input?
Consider the Kadane's algorithm for finding maximum subarray within an array:
def max_subarray(numbers):
"""Find the largest sum of any contiguous subarray."""
best_sum = 0
current_sum = 0
for x in numbers:
current_sum =…
Eugene Yarmash
- 275
- 3
- 8
7
votes
2 answers
Space complexity of string indices: O(1) or O(log|S|)?
Say you have a string S and wish to store indices of it, e.g. letter at index 3 of "toast" is 'a'. Seems that people generally consider an index as taking O(1) space to store*. But doesn't it take O(log(|S|)) space?
If we use binary bits...
length…
sudo
- 173
- 6
7
votes
1 answer
Can anybody explain intuitively why quick sort need log(n) extra space and mergesort need n?
I've searched on internet and everybody said it's stack space needed on recursion. I know log(n) extra space for quick sort happened when use in place, but still I don't get it. Anybody can explain intuitively why quick sort need log(n) extra space…
Guest
- 79
- 1
- 1
- 2
6
votes
1 answer
Memory needed for computational graph
Suppose we have a set of equations like this
p7=f(p1+p6); p6=f(p2+p5); p5=f(p3+p4); p4=f(p3); p3=f(p2); p2=f(p1); p1=f()
It can be represented by computational graph below
If each intermediate value takes 1 unit of memory, you need at least 4…
Yaroslav Bulatov
- 201
- 2
- 12
6
votes
1 answer
Showing strong connectivity is in DSPACE((logn)^2)
$ST-CONN = \text{{(G,s,t) | G is directed graph, there's path from s to t}}$
I've learned the following deterministic algorithm to solve the problem in $log^2n$ space:
$\psi(G,s,t,k) :$
$\hspace{1cm}\text{if k == 1: return 1 if there's edge from s…
sel
- 385
- 2
- 7
6
votes
1 answer
How to compute $\mathbf{X}^T \mathbf{X}$ efficiently for large $\mathbf{X}$?
Let $\mathbf{X}$ be a $n \times n$ matrix. Given that we can only keep $k$ rows ($k << n$) or columns of the matrix in memory, how can we compute $\mathbf{X}^T \mathbf{X}$ while minimizing the number of disk accesses?
Are there known algorithms for…
erensezener
- 248
- 1
- 8
5
votes
3 answers
Memory usage of a BST or hash table?
I would like to use a data structure allowing fast access, either a balanced binary search tree (BST) for $O(\log n)$ access time or an open hash table for constant access time.
1) What is the exact memory usage of a BST or hash table, for storing…
user7060
- 475
- 5
- 12
5
votes
1 answer
Since we need space for recursive calls, is the space complexity of the recursive factorial is n?
As Wikipedia says, quickSort needs O(log n) extra space when the following conditions are met:
In-place partitioning is used. This unstable partition requires O(1)
space.
After partitioning, the partition with the fewest elements is
(recursively)…
Maksim Dmitriev
- 413
- 1
- 3
- 14
4
votes
1 answer
Is FKS hashing really linear space?
In FKS hashing, I wonder if the size of the table $G[1..n]$ (used to record the functions $g_i$ which is chosen randomly; one entry per bucket) is really strictly $O(n)$. Given that the probability of a hash function $g_i$ is higher than 0.5, I can…
Thomas Mueller
- 203
- 1
- 8
4
votes
2 answers
Space complexity of directed and undirected graph
I have started reading graph theory from Introduction to Algorithm. The author starts by saying that if the graph is dense then:
$$|E|\text{ close to }|V|^2$$ else if the graph is sparse then:
$$|E|\text{ is much less than }|V^2|$$
According to me…
CodeYogi
- 281
- 2
- 9
3
votes
5 answers
Chess Knight minimum moves to destination on an infinite board
There are tones of solutions for Knights tour or shortest path for Knights movement from source cell to destination cell. most of the solutions are using BFS which seems the best algorithm.
Here is my implementation using HashMap:
public class…
Amir-Mousavi
- 268
- 2
- 13
3
votes
1 answer
A* 8-puzzle problem worst case memory usage
We are testing the A* algorithm with Hamming and Manhattan on the 8-puzzle (and its natural generalization n-puzzle) problem.
We have to answer the following question but I can't figure out what it should be.
Our assignment is derived from this.…
Principis
- 31
- 2
3
votes
1 answer
Recurrence: space complexity to Tournament Method
Tournament method have this structure to found min and max (function getMinMax):
mid = (low + high)/2;
mml = getMinMax(arr, low, mid);
mmr = getMinMax(arr, mid+1, high);
/* compare minimums of two parts*/
if (mml.min < mmr.min)
…
eightShirt
- 143
- 1
- 1
- 8