Вопрос

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