In-place algorithm
In computer science, an in-place algorithm is an algorithm that operates directly on the input data structure without requiring extra space proportional to the input size. In other words, it modifies the input in place, without creating a separate copy of the data structure. An algorithm which is not in-place is sometimes called not-in-place or out-of-place. In-place can have slightly different meanings. In its strictest form, the algorithm can only have a constant amount of extra space, counting everything including function calls and pointers. However, this form is very limited as simply having an index to a length array requires bits. More broadly, in-place means that the algorithm does not use extra space for manipulating the input but may require a small though non-constant extra space for its operation. Usually, this space is , though sometimes anything in is allowed. Note that space complexity also has varied choices in whether or not to count the index lengths as part of the space used. Often, the space complexity is given in terms of the number of indices or pointers needed, ignoring their length. In this article, we refer to total space complexity (DSPACE), counting pointer lengths. Therefore, the space requirements here have an extra factor compared to an analysis that ignores the lengths of indices and pointers.…
In computer science, an in-place algorithm is an algorithm that operates directly on the input data structure without requiring extra space proportional to the input size. In other words, it modifies the input in place, without creating a separate copy of the data structure. An algorithm which is not in-place is sometimes called not-in-place or out-of-place. In-place can have slightly different meanings. In its strictest form, the algorithm can only have a constant amount of extra space, counting everything including function calls and pointers. However, this form is very limited as simply having an index to a length array requires bits. More broadly, in-place means that the algorithm does not use extra space for manipulating the input but may require a small though non-constant extra space for its operation. Usually, this space is , though sometimes anything in is allowed. Note that space complexity also has varied choices in whether or not to count the index lengths as part of the space used. Often, the space complexity is given in terms of the number of indices or pointers needed, ignoring their length. In this article, we refer to total space complexity (DSPACE), counting pointer lengths. Therefore, the space requirements here have an extra factor compared to an analysis that ignores the lengths of indices and pointers. An algorithm may or may not count the output as part of its space usage. Since in-place algorithms usually overwrite their input with output, no additional space is needed. 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. In theoretical applications such as log-space reductions, it is more typical to always ignore output space (in these cases it is more essential that the output is write-only). b[n − 1 − i] := a[i] return b Unfortunately, this requires extra space for having the arrays and available simultaneously. Also, allocation and deallocation are often slow operations. Since we no longer need , we can instead overwrite it with its own reversal using this in-place algorithm which will only need constant number (2) of integers for the auxiliary variables and , no matter how large the array is. function reverse_in_place(a[0..n-1]) for i from 0 to floor((n-2)/2) tmp := a[i] a[i] := a[n − 1 − i] a[n − 1 − i] := tmp As another example, many sorting algorithms rearrange arrays into sorted order in-place, including: bubble sort, comb sort, selection sort, insertion sort, heapsort, and Shell sort. These algorithms require only a few pointers, so their space complexity is . Quicksort operates in-place on the data to be sorted. However, quicksort requires stack space pointers to keep track of the subarrays in its divide and conquer strategy. Consequently, quicksort needs additional space. Although this non-constant space technically takes quicksort out of the in-place category, quicksort and other algorithms needing only additional pointers are usually considered in-place algorithms. Most selection algorithms are also in-place, although some considerably rearrange the input array in the process of finding the final, constant-sized result. Some text manipulation algorithms such as trim and reverse may be done in-place.
References
- The bit space requirement of a pointer is O (log n ) , but pointer size can be considered a constant in most sorting applications. Wikipedia revision 1355535482, retrieved 2026-11-22 · retrieved 2026-11-21 · rev 1355535482
Cite this reference
MLA "The bit space requirement of a pointer is O (log n ) , but pointer size can be considered a constant in most sorting applications. Wikipedia revision 1355535482, retrieved 2026-11-22." The bit space requirement of a pointer is O (log n ) , but pointer size can be considered a constant in most sorting app. 2026-11-21. https://en.wikipedia.org/w/index.php?oldid=1355535482. Accessed 24 November 2026.
Chicago "The bit space requirement of a pointer is O (log n ) , but pointer size can be considered a constant in most sorting applications. Wikipedia revision 1355535482, retrieved 2026-11-22." The bit space requirement of a pointer is O (log n ) , but pointer size can be considered a constant in most sorting app. 2026-11-21. https://en.wikipedia.org/w/index.php?oldid=1355535482.
APA The bit space requirement of a pointer is O (log n ) , but pointer size can be considered a constant in most sorting app. (2026). The bit space requirement of a pointer is O (log n ) , but pointer size can be considered a constant in most sorting applications. Wikipedia revision 1355535482, retrieved 2026-11-22. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1355535482
- Maciej Liśkiewicz and Rüdiger Reischuk. The Complexity World below Logarithmic Space . Structure in Complexity Theory Conference , pp. 64–78. 1994. Online: p. 3, Theorem 2. Wikipedia revision 1355535482, retrieved 2026-11-22 · retrieved 2026-11-21 · rev 1355535482
Cite this reference
MLA "Maciej Liśkiewicz and Rüdiger Reischuk. The Complexity World below Logarithmic Space . Structure in Complexity Theory Conference , pp. 64–78. 1994. Online: p. 3, Theorem 2. Wikipedia revision 1355535482, retrieved 2026-11-22." Maciej Liśkiewicz and Rüdiger Reischuk. 2026-11-21. http://citeseer.ist.psu.edu/34203.html. Accessed 24 November 2026.
Chicago "Maciej Liśkiewicz and Rüdiger Reischuk. The Complexity World below Logarithmic Space . Structure in Complexity Theory Conference , pp. 64–78. 1994. Online: p. 3, Theorem 2. Wikipedia revision 1355535482, retrieved 2026-11-22." Maciej Liśkiewicz and Rüdiger Reischuk. 2026-11-21. http://citeseer.ist.psu.edu/34203.html.
APA Maciej Liśkiewicz and Rüdiger Reischuk. (2026). Maciej Liśkiewicz and Rüdiger Reischuk. The Complexity World below Logarithmic Space . Structure in Complexity Theory Conference , pp. 64–78. 1994. Online: p. 3, Theorem 2. Wikipedia revision 1355535482, retrieved 2026-11-22. Retrieved November 24, 2026, from http://citeseer.ist.psu.edu/34203.html
- Undirected connectivity in log-space · retrieved 2026-11-21 · rev 1355535482
Cite this reference
MLA "Undirected connectivity in log-space." Reingold, Omer (2008), "Undirected connectivity in log-space", Journal of the ACM , 55 (4): 1– 24, doi : 10. 2026-11-21. https://en.wikipedia.org/wiki/Omer_Reingold. Accessed 24 November 2026.
Chicago "Undirected connectivity in log-space." Reingold, Omer (2008), "Undirected connectivity in log-space", Journal of the ACM , 55 (4): 1– 24, doi : 10. 2026-11-21. https://en.wikipedia.org/wiki/Omer_Reingold.
APA Reingold, Omer (2008), "Undirected connectivity in log-space", Journal of the ACM , 55 (4): 1– 24, doi : 10. (2026). Undirected connectivity in log-space. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Omer_Reingold
- Maciej Liśkiewicz and Rüdiger Reischuk. [http://citeseer.ist.psu.edu/34203.html The Complexity World below Logarithmic Space]. Structure in Complexity Theory Conference, pp. 64–78. 1994. Online: p . · retrieved 2026-05-21 · rev 1355535482
Cite this reference
MLA "Maciej Liśkiewicz and Rüdiger Reischuk. [http://citeseer.ist.psu.edu/34203.html The Complexity World below Logarithmic Space]. Structure in Complexity Theory Conference, pp. 64–78. 1994. Online: p ." Maciej Liśkiewicz and Rüdiger Reischuk. 2026-05-21. https://en.wikipedia.org/w/index.php?oldid=1355535482. Accessed 24 November 2026.
Chicago "Maciej Liśkiewicz and Rüdiger Reischuk. [http://citeseer.ist.psu.edu/34203.html The Complexity World below Logarithmic Space]. Structure in Complexity Theory Conference, pp. 64–78. 1994. Online: p ." Maciej Liśkiewicz and Rüdiger Reischuk. 2026-05-21. https://en.wikipedia.org/w/index.php?oldid=1355535482.
APA Maciej Liśkiewicz and Rüdiger Reischuk. (2026). Maciej Liśkiewicz and Rüdiger Reischuk. [http://citeseer.ist.psu.edu/34203.html The Complexity World below Logarithmic Space]. Structure in Complexity Theory Conference, pp. 64–78. 1994. Online: p . Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1355535482
Cite this article
MLA
"In-place algorithm." encyclopegia.org, 2026, https://encyclopegia.org/wiki/in-place-algorithm. Accessed 24 November 2026.
Chicago
"In-place algorithm." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/in-place-algorithm.
APA
encyclopegia.org. (2026). In-place algorithm. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/in-place-algorithm
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON