Skip to content

Commit fc430eb

Browse files
author
barbara
committed
Merge branch 'splay-tree' of github.com:barbaramartina/swift-algorithm-club into splay-tree
2 parents 7f75191 + d2f02ef commit fc430eb

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

Splay Tree/readme.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,60 @@
1-
In progress
1+
# Splay Tree
2+
Splay tree is a data structure, structurally identitical to a Balanced Binary Search Tree. Every operation performed on a Splay Tree causes a readjustment in order to provide fast access to recently operated values. On every access, the tree is rearranged and the node accessed is moved to the root of the tree using a set of specific rotations, which together are referred to as **Splaying**.
3+
4+
5+
## Rotations
6+
7+
### Zig-Zig
8+
9+
Given a node *a* if *a* is not the root, and *a* has a child *b*, and both *a* and *b* are left children or right children, a **Zig-Zig** is performed.
10+
11+
### Zig-Zag
12+
13+
Given a node *a* if *a* is not the root, and *a* has a child *b*, and *b* is the left child of *a* being the right child (or the opporsite), a **Zig-Zag** is performed.
14+
15+
### Zig
16+
17+
A **Zig** is performed when the node *a* to be rotated has the root as parent.
18+
19+
## Splaying
20+
21+
## Operations
22+
23+
### Insertion
24+
25+
### Deletion
26+
27+
### Search
28+
29+
## Examples
30+
31+
### Example 1
32+
33+
### Example 2
34+
35+
### Example 3
36+
37+
## Advantages
38+
39+
Splay trees provide an efficient way to quickly access elements that are frequently requested. This characteristic makes then a good choice to implement, for exmaple, caches or garbage collection algorithms, or in any other problem involving frequent access to a certain numbers of elements from a data set.
40+
41+
## Disadvantages
42+
43+
Splay tree are not perfectly balanced always, so in case of accessing all the elements in the tree in an increasing order, the height of the tree becomes *n*.
44+
45+
## Time complexity
46+
47+
| Case | Performance |
48+
| ------------- |:-------------:|
49+
| Average | O(log n) |
50+
| Worst | n |
51+
52+
With *n* being the number of items in the tree.
53+
54+
55+
## See also
56+
57+
[Splay Tree on Wikipedia](https://en.wikipedia.org/wiki/Splay_tree)
58+
[Splay Tree by University of California in Berkeley - CS 61B Lecture 34](https://www.youtube.com/watch?v=G5QIXywcJlY)
59+
60+
*Written for Swift Algorithm Club by Mike Taghavi and Matthijs Hollemans*

0 commit comments

Comments
 (0)