Differences between time complexity and space complexity?

后端 未结 7 2291
北荒
北荒 2020-12-12 10:04

I have seen that in most cases the time complexity is related to the space complexity and vice versa. For example in an array traversal:

for i=1 to length(v)         


        
相关标签:
7条回答
  • 2020-12-12 10:51

    First of all, the space complexity of this loop is O(1) (the input is customarily not included when calculating how much storage is required by an algorithm).

    So the question that I have is if its possible that an algorithm has different time complexity from space complexity?

    Yes, it is. In general, the time and the space complexity of an algorithm are not related to each other.

    Sometimes one can be increased at the expense of the other. This is called space-time tradeoff.

    0 讨论(0)
提交回复
热议问题