When and where to use the terms: time complexity, space complexity?

Asked

Viewed 776 times

3

I’m using the book Data Structures: Algorithms, Complexity Analysis and Implementations in JAVA and C/C++ as it helps with practical implementation examples.

In chapter 1 there is the following excerpt that left me in doubt

The running time of an algorithm will be represented by a cost function T, where T(n) is the measure of the time needed to execute an algorithm for a problem of size n. Hence, T is called 'time complexity function' of the algorithm. If T(n) is the memory measure needed to execute the algorithm, then T is called 'space complexity function. According to Ziviani (2004), it is important to emphasize that T(n) does not directly represent the execution time, but the number of times a relevant operation is executed.

Why does the author refer to T in two different ways? it became difficult to understand this variation, has some context in which another expression should be used?

1 answer

3


Because it has to do with two things. Complexity can be measured in these two axes: runtime and occupied space. These are the factors that matter when creating or using an algorithm. How long it takes (relatively) to perform and how much it needs memory (proportionally).

Maybe the text is lumped together and creates confusion, so read it like this:

The running time of an algorithm will be represented by a cost function T, where T(n) is the measure of the time needed to execute an algorithm for a problem of size n. Hence, T is called the 'time complexity function' of the algorithm. It is important to emphasize that T(n) does not directly represent the execution time, but the number of times a certain relevant operation is executed

You got that part?

Now read this new one in isolation because you’re still talking about complexity, but on another axis, so you use the same notation, but you’re talking about something else:

If T(n) is the measure of memory needed to execute the algorithm, then T is called 'space complexity function

And I add that it has to do with the amount of elements and not with the actual space occupied.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.