In-place algorithm

In its strictest form, the algorithm can only have a constant amount of extra space, counting everything including function calls and pointers.

Therefore, the space requirements here have an extra log n factor compared to an analysis that ignores the lengths of indices and pointers.

When writing the output to write-only memory or a stream, it may be more appropriate to only consider the working space of the algorithm.

One seemingly simple way to do this is to create a new array of equal size, fill it with copies from a in the appropriate order and then delete a.

However, quicksort requires O(log n) stack space pointers to keep track of the subarrays in its divide and conquer strategy.

Most selection algorithms are also in-place, although some considerably rearrange the input array in the process of finding the final, constant-sized result.

Algorithms are usually considered in L, the class of problems requiring O(log n) additional space, to be in-place.

However, good functional language compilers will often recognize when an object very similar to an existing one is created and then the old one is thrown away, and will optimize this into a simple mutation "under the hood".