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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top