<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
an	O
in-place	B-Algorithm
algorithm	I-Algorithm
is	O
an	O
algorithm	O
which	O
transforms	O
input	O
using	O
no	O
auxiliary	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
An	O
in-place	B-Algorithm
algorithm	I-Algorithm
updates	O
its	O
input	O
sequence	O
only	O
through	O
replacement	O
or	O
swapping	O
of	O
elements	O
.	O
</s>
<s>
An	O
algorithm	O
which	O
is	O
not	O
in-place	B-Algorithm
is	O
sometimes	O
called	O
not-in-place	B-Algorithm
or	O
out-of-place	O
.	O
</s>
<s>
In-place	B-Algorithm
can	O
have	O
slightly	O
different	O
meanings	O
.	O
</s>
<s>
However	O
,	O
this	O
form	O
is	O
very	O
limited	O
as	O
simply	O
having	O
an	O
index	O
to	O
a	O
length	O
array	B-Data_Structure
requires	O
bits	O
.	O
</s>
<s>
More	O
broadly	O
,	O
in-place	B-Algorithm
means	O
that	O
the	O
algorithm	O
does	O
not	O
use	O
extra	O
space	O
for	O
manipulating	O
the	O
input	O
but	O
may	O
require	O
a	O
small	O
though	O
nonconstant	O
extra	O
space	O
for	O
its	O
operation	O
.	O
</s>
<s>
Since	O
in-place	B-Algorithm
algorithms	I-Algorithm
usually	O
overwrite	O
their	O
input	O
with	O
output	O
,	O
no	O
additional	O
space	O
is	O
needed	O
.	O
</s>
<s>
In	O
theoretical	O
applications	O
such	O
as	O
log-space	B-Algorithm
reductions	I-Algorithm
,	O
it	O
is	O
more	O
typical	O
to	O
always	O
ignore	O
output	O
space	O
(	O
in	O
these	O
cases	O
it	O
is	O
more	O
essential	O
that	O
the	O
output	O
is	O
write-only	O
)	O
.	O
</s>
<s>
Given	O
an	O
array	B-Data_Structure
of	O
items	O
,	O
suppose	O
we	O
want	O
an	O
array	B-Data_Structure
that	O
holds	O
the	O
same	O
elements	O
in	O
reversed	O
order	O
and	O
to	O
dispose	O
of	O
the	O
original	O
.	O
</s>
<s>
One	O
seemingly	O
simple	O
way	O
to	O
do	O
this	O
is	O
to	O
create	O
a	O
new	O
array	B-Data_Structure
of	O
equal	O
size	O
,	O
fill	O
it	O
with	O
copies	O
from	O
in	O
the	O
appropriate	O
order	O
and	O
then	O
delete	O
.	O
</s>
<s>
Since	O
we	O
no	O
longer	O
need	O
,	O
we	O
can	O
instead	O
overwrite	O
it	O
with	O
its	O
own	O
reversal	O
using	O
this	O
in-place	B-Algorithm
algorithm	I-Algorithm
which	O
will	O
only	O
need	O
constant	O
number	O
(	O
2	O
)	O
of	O
integers	O
for	O
the	O
auxiliary	O
variables	O
and	O
,	O
no	O
matter	O
how	O
large	O
the	O
array	B-Data_Structure
is	O
.	O
</s>
<s>
As	O
another	O
example	O
,	O
many	O
sorting	B-Algorithm
algorithms	I-Algorithm
rearrange	O
arrays	O
into	O
sorted	O
order	O
in-place	B-Algorithm
,	O
including	O
:	O
bubble	B-Algorithm
sort	I-Algorithm
,	O
comb	B-Algorithm
sort	I-Algorithm
,	O
selection	B-Algorithm
sort	I-Algorithm
,	O
insertion	B-Algorithm
sort	I-Algorithm
,	O
heapsort	B-Application
,	O
and	O
Shell	B-Algorithm
sort	I-Algorithm
.	O
</s>
<s>
Quicksort	B-Algorithm
operates	O
in-place	B-Algorithm
on	O
the	O
data	O
to	O
be	O
sorted	O
.	O
</s>
<s>
However	O
,	O
quicksort	B-Algorithm
requires	O
stack	O
space	O
pointers	O
to	O
keep	O
track	O
of	O
the	O
subarrays	O
in	O
its	O
divide	B-Algorithm
and	I-Algorithm
conquer	I-Algorithm
strategy	O
.	O
</s>
<s>
Consequently	O
,	O
quicksort	B-Algorithm
needs	O
additional	O
space	O
.	O
</s>
<s>
Although	O
this	O
non-constant	O
space	O
technically	O
takes	O
quicksort	B-Algorithm
out	O
of	O
the	O
in-place	B-Algorithm
category	O
,	O
quicksort	B-Algorithm
and	O
other	O
algorithms	O
needing	O
only	O
additional	O
pointers	O
are	O
usually	O
considered	O
in-place	B-Algorithm
algorithms	I-Algorithm
.	O
</s>
<s>
Most	O
selection	B-Algorithm
algorithms	I-Algorithm
are	O
also	O
in-place	B-Algorithm
,	O
although	O
some	O
considerably	O
rearrange	O
the	O
input	O
array	B-Data_Structure
in	O
the	O
process	O
of	O
finding	O
the	O
final	O
,	O
constant-sized	O
result	O
.	O
</s>
<s>
Some	O
text	O
manipulation	O
algorithms	O
such	O
as	O
trim	O
and	O
reverse	O
may	O
be	O
done	O
in-place	B-Algorithm
.	O
</s>
<s>
In	O
computational	O
complexity	O
theory	O
,	O
the	O
strict	O
definition	O
of	O
in-place	B-Algorithm
algorithms	I-Algorithm
includes	O
all	O
algorithms	O
with	O
space	O
complexity	O
,	O
the	O
class	O
DSPACE(1 )	O
.	O
</s>
<s>
This	O
class	O
is	O
very	O
limited	O
;	O
it	O
equals	O
the	O
regular	B-General_Concept
languages	I-General_Concept
.	O
</s>
<s>
Algorithms	O
are	O
usually	O
considered	O
in	O
L	O
,	O
the	O
class	O
of	O
problems	O
requiring	O
additional	O
space	O
,	O
to	O
be	O
in-place	B-Algorithm
.	O
</s>
<s>
This	O
expanded	O
definition	O
still	O
excludes	O
quicksort	B-Algorithm
,	O
however	O
,	O
because	O
of	O
its	O
recursive	O
calls	O
.	O
</s>
<s>
Identifying	O
the	O
in-place	B-Algorithm
algorithms	I-Algorithm
with	O
L	O
has	O
some	O
interesting	O
implications	O
;	O
for	O
example	O
,	O
it	O
means	O
that	O
there	O
is	O
a	O
(	O
rather	O
complex	O
)	O
in-place	B-Algorithm
algorithm	I-Algorithm
to	O
determine	O
whether	O
a	O
path	O
exists	O
between	O
two	O
nodes	O
in	O
an	O
undirected	O
graph	O
,	O
a	O
problem	O
that	O
requires	O
extra	O
space	O
using	O
typical	O
algorithms	O
such	O
as	O
depth-first	B-Algorithm
search	I-Algorithm
(	O
a	O
visited	O
bit	O
for	O
each	O
node	O
)	O
.	O
</s>
<s>
This	O
in	O
turn	O
yields	O
in-place	B-Algorithm
algorithms	I-Algorithm
for	O
problems	O
such	O
as	O
determining	O
if	O
a	O
graph	O
is	O
bipartite	O
or	O
testing	O
whether	O
two	O
graphs	O
have	O
the	O
same	O
number	O
of	O
connected	O
components	O
.	O
</s>
<s>
In	O
many	O
cases	O
,	O
the	O
space	O
requirements	O
of	O
an	O
algorithm	O
can	O
be	O
drastically	O
cut	O
by	O
using	O
a	O
randomized	B-General_Concept
algorithm	I-General_Concept
.	O
</s>
<s>
For	O
example	O
,	O
if	O
one	O
wishes	O
to	O
know	O
if	O
two	O
vertices	O
in	O
a	O
graph	O
of	O
vertices	O
are	O
in	O
the	O
same	O
connected	O
component	O
of	O
the	O
graph	O
,	O
there	O
is	O
no	O
known	O
simple	O
,	O
deterministic	O
,	O
in-place	B-Algorithm
algorithm	I-Algorithm
to	O
determine	O
this	O
.	O
</s>
<s>
Similarly	O
,	O
there	O
are	O
simple	O
randomized	O
in-place	B-Algorithm
algorithms	I-Algorithm
for	O
primality	O
testing	O
such	O
as	O
the	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
primality	I-Algorithm
test	I-Algorithm
,	O
and	O
there	O
are	O
also	O
simple	O
in-place	B-Algorithm
randomized	O
factoring	O
algorithms	O
such	O
as	O
Pollard	B-Algorithm
's	I-Algorithm
rho	I-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
Functional	B-Language
programming	I-Language
languages	I-Language
often	O
discourage	O
or	O
do	O
not	O
support	O
explicit	O
in-place	B-Algorithm
algorithms	I-Algorithm
that	O
overwrite	O
data	O
,	O
since	O
this	O
is	O
a	O
type	O
of	O
side	O
effect	O
;	O
instead	O
,	O
they	O
only	O
allow	O
new	O
data	O
to	O
be	O
constructed	O
.	O
</s>
<s>
However	O
,	O
good	O
functional	B-Language
language	I-Language
compilers	O
will	O
often	O
recognize	O
when	O
an	O
object	O
very	O
similar	O
to	O
an	O
existing	O
one	O
is	O
created	O
and	O
then	O
the	O
old	O
one	O
is	O
thrown	O
away	O
,	O
and	O
will	O
optimize	O
this	O
into	O
a	O
simple	O
mutation	O
"	O
under	O
the	O
hood	O
"	O
.	O
</s>
<s>
Note	O
that	O
it	O
is	O
possible	O
in	O
principle	O
to	O
carefully	O
construct	O
in-place	B-Algorithm
algorithms	I-Algorithm
that	O
do	O
not	O
modify	O
data	O
(	O
unless	O
the	O
data	O
is	O
no	O
longer	O
being	O
used	O
)	O
,	O
but	O
this	O
is	O
rarely	O
done	O
in	O
practice	O
.	O
</s>
