<s>
The	O
Day	O
–	O
Stout	O
–	O
Warren	O
(	O
DSW	O
)	O
algorithm	O
is	O
a	O
method	O
for	O
efficiently	O
balancing	O
binary	B-Language
search	I-Language
trees	I-Language
that	O
is	O
,	O
decreasing	O
their	O
height	O
to	O
O(log n )	O
nodes	O
,	O
where	O
n	O
is	O
the	O
total	O
number	O
of	O
nodes	O
.	O
</s>
<s>
Unlike	O
a	O
self-balancing	B-Data_Structure
binary	I-Data_Structure
search	I-Data_Structure
tree	I-Data_Structure
,	O
it	O
does	O
not	O
do	O
this	O
incrementally	O
during	O
each	O
operation	O
,	O
but	O
periodically	O
,	O
so	O
that	O
its	O
cost	O
can	O
be	O
amortized	B-General_Concept
over	O
many	O
operations	O
.	O
</s>
<s>
The	O
algorithm	O
requires	O
linear	O
(O(n )	O
)	O
time	O
and	O
is	O
in-place	B-Algorithm
.	O
</s>
<s>
First	O
,	O
the	O
tree	O
is	O
turned	O
into	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
by	O
means	O
of	O
an	O
in-order	O
traversal	O
,	O
reusing	O
the	O
pointers	O
in	O
the	O
(	O
threaded	B-Data_Structure
)	O
tree	O
's	O
nodes	O
.	O
</s>
<s>
A	O
series	O
of	O
left-rotations	B-Data_Structure
forms	O
the	O
second	O
phase	O
.	O
</s>
<s>
It	O
does	O
not	O
require	O
the	O
tree	O
to	O
be	O
threaded	B-Data_Structure
,	O
nor	O
does	O
it	O
require	O
more	O
than	O
constant	O
space	O
to	O
operate	O
.	O
</s>
<s>
A	O
2002	O
article	O
by	O
Timothy	O
J	O
.	O
Rolfe	O
brought	O
attention	O
back	O
to	O
the	O
DSW	B-Data_Structure
algorithm	I-Data_Structure
;	O
the	O
naming	O
is	O
from	O
the	O
section	O
title	O
"	O
6.7.1	O
:	O
The	O
DSW	B-Data_Structure
Algorithm	I-Data_Structure
"	O
in	O
Adam	O
Drozdek	O
's	O
textbook	O
.	O
</s>
<s>
Rolfe	O
cites	O
two	O
main	O
advantages	O
:	O
"	O
in	O
circumstances	O
in	O
which	O
one	O
generates	O
an	O
entire	O
binary	B-Language
search	I-Language
tree	I-Language
at	O
the	O
beginning	O
of	O
processing	O
,	O
followed	O
by	O
item	O
look-up	O
access	O
for	O
the	O
rest	O
of	O
processing	O
"	O
and	O
"	O
pedagogically	O
within	O
a	O
course	O
on	O
data	O
structures	O
where	O
one	O
progresses	O
from	O
the	O
binary	B-Language
search	I-Language
tree	I-Language
into	O
self-adjusting	O
trees	O
,	O
since	O
it	O
gives	O
a	O
first	O
exposure	O
to	O
doing	O
rotations	O
within	O
a	O
binary	O
search	O
tree.	O
"	O
</s>
<s>
The	O
following	O
is	O
a	O
presentation	O
of	O
the	O
basic	O
DSW	B-Data_Structure
algorithm	I-Data_Structure
in	O
pseudocode	B-Language
,	O
after	O
the	O
Stout	O
–	O
Warren	O
paper	O
.	O
</s>
<s>
//	O
Convert	O
tree	O
to	O
a	O
"	O
vine	O
"	O
,	O
i.e.	O
,	O
a	O
sorted	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
</s>
