Question

I had made the comparison in between 2 algorithms, A and B. I found that, the time complexity of these 2 algorithms is different, which are O(n^3) and O(n^4) respectively, but the space complexity of both A and B is same, which is O(n). Is that have probability?

Was it helpful?

Solution

That is possible, yes. The time complexity and the space complexity are not necessarily related to each other.

As an example, think of various sorting algorithms, such as the ones in this list - as you see, both insertion sort and heapsort have a space-complexity (column memory) of O(1), while their time complexities are different.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top