5
5
6
6
/**
7
7
* Implementation of a Splay Tree data structure.
8
- *
9
- * A splay tree is a self-adjusting binary search tree with the additional property
8
+ *
9
+ * A splay tree is a self-adjusting binary search tree with the additional
10
+ * property
10
11
* that recently accessed elements are quick to access again. It performs basic
11
- * operations such as insertion, deletion, and searching in O(log n) amortized time,
12
+ * operations such as insertion, deletion, and searching in O(log n) amortized
13
+ * time,
12
14
* where n is the number of elements in the tree.
13
- *
14
- * The key feature of splay trees is the splay operation, which moves a node closer
15
+ *
16
+ * The key feature of splay trees is the splay operation, which moves a node
17
+ * closer
15
18
* to the root of the tree when it is accessed. This operation helps to maintain
16
- * good balance and improves the overall performance of the tree. After performing
19
+ * good balance and improves the overall performance of the tree. After
20
+ * performing
17
21
* a splay operation, the accessed node becomes the new root of the tree.
18
- *
19
- * Splay trees have applications in various areas, including caching, network routing,
22
+ *
23
+ * Splay trees have applications in various areas, including caching, network
24
+ * routing,
20
25
* and dynamic optimality analysis.
21
26
*/
22
27
public class SplayTree {
@@ -102,8 +107,10 @@ public List<Integer> traverse(TreeTraversal traversal) {
102
107
* Zig operation.
103
108
*
104
109
* <p>
105
- * The zig operation is used to perform a single rotation on a node to move it closer to
106
- * the root of the tree. It is typically applied when the node is a left child of its parent
110
+ * The zig operation is used to perform a single rotation on a node to move it
111
+ * closer to
112
+ * the root of the tree. It is typically applied when the node is a left child
113
+ * of its parent
107
114
* and needs to be rotated to the right.
108
115
* </p>
109
116
*
@@ -121,8 +128,10 @@ private Node rotateRight(Node x) {
121
128
* Zag operation.
122
129
*
123
130
* <p>
124
- * The zag operation is used to perform a single rotation on a node to move it closer to
125
- * the root of the tree. It is typically applied when the node is a right child of its parent
131
+ * The zag operation is used to perform a single rotation on a node to move it
132
+ * closer to
133
+ * the root of the tree. It is typically applied when the node is a right child
134
+ * of its parent
126
135
* and needs to be rotated to the left.
127
136
* </p>
128
137
*
@@ -140,23 +149,28 @@ private Node rotateLeft(Node x) {
140
149
* Splay operation.
141
150
*
142
151
* <p>
143
- * The splay operation is the core operation of a splay tree. It moves a specified node
144
- * closer to the root of the tree by performing a series of rotations. The goal of the splay
145
- * operation is to improve the access time for frequently accessed nodes by bringing them
152
+ * The splay operation is the core operation of a splay tree. It moves a
153
+ * specified node
154
+ * closer to the root of the tree by performing a series of rotations. The goal
155
+ * of the splay
156
+ * operation is to improve the access time for frequently accessed nodes by
157
+ * bringing them
146
158
* closer to the root.
147
159
* </p>
148
160
*
149
161
* <p>
150
162
* The splay operation consists of three main cases:
151
163
* <ul>
152
164
* <li>Zig-Zig case: Perform two consecutive rotations.</li>
153
- * <li>Zig-Zag case: Perform two consecutive rotations in opposite directions.</li>
165
+ * <li>Zig-Zag case: Perform two consecutive rotations in opposite
166
+ * directions.</li>
154
167
* <li>Zag-Zag case: Perform two consecutive rotations.</li>
155
168
* </ul>
156
169
* </p>
157
170
*
158
171
* <p>
159
- * After performing the splay operation, the accessed node becomes the new root of the tree.
172
+ * After performing the splay operation, the accessed node becomes the new root
173
+ * of the tree.
160
174
* </p>
161
175
*
162
176
* @param root The root of the subtree to splay.
0 commit comments