문제

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