It is the amount of memory which is needed by the algorithm (program) to run to completion. We can measure the space by finding out that how much memory will be consumed by the instructions and by the variables used.
E.g.
Suppose we want to add two integer numbers. To solve this problem we have following two algorithms:
Both algorithms will produce the same result. But first takes 6 bytes and second takes 4 bytes (2 bytes for each integer). And first has more instructions than the second one. So we will choose the second one as it takes less space than the first one.
Reasons for measuring the space complexity
1. If the program is to be run on multiuser system, then we will have to specify the amount of memory to be allocated to the program.
2. To know in advance whether enough memory is available for the program or not.
3. There can be several solutions for the problem with different space requirements and we have to choose that which takes least space among them.
4. It can be used to estimate the size of the largest problem that a program can solve.