My book states that for a code with T(n) time complexity and S(n) space complexity, the following statement holds: T(n) is omega(S(n)). My question is: Why does this statement hold?
Asked
Active
Viewed 345 times
-3
-
2Because it takes time to allocate space. – kaya3 Feb 28 '20 at 18:11
-
Please refer to https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions – xibalba1 Feb 28 '20 at 18:12
-
1Because think like this. To create array of `n^2` element it will atleast take `n^2` time. So any time you cannot allocate for example `n` elements in constant time `O(1)`. And thus space complexity will always be lower bound of time complexity. – Poojan Feb 28 '20 at 18:13
-
Keep in mind that space complexity doesn't include the space occupied by the input. (For example, binary search on an array has logarithmic time complexity but constant space complexity.) – chepner Feb 28 '20 at 18:15
-
Does this answer your question? [Differences between time complexity and space complexity?](https://stackoverflow.com/questions/18686121/differences-between-time-complexity-and-space-complexity) – Dima Chubarov Feb 28 '20 at 18:18
-
2Strictly speaking, if you're writing very low-level code (i.e. not Python) that is allowed to ask for memory without having it zeroed out first, then you can write algorithms which use "more space than time". There's a nice example in one of the early exercises in *Programming Pearls* by John Bentley, of using two uninitialised arrays to represent a set of integers; the number `i` is in the set if and only if `arr1[i] < size` and `arr2[arr1[i]] == i`. The idea is that you can write at random positions in `arr1` and use `arr2` to confirm whether a position in `arr1` has been written or not. – kaya3 Feb 28 '20 at 18:23
1 Answers
5
We are speaking of sequential algorithms.
Then space complexity S(n) means that the algorithm somehow inspects each of S(n) different memory locations at least once. In order to visit this many memory locations a sequential algorithm needs Ω(S(n)) time.

Dima Chubarov
- 16,199
- 6
- 40
- 76