Kalkwst / MicroLib

MIT License
3 stars 0 forks source link

:sparkles: Add Splay Tree Implementation #41

Open Kalkwst opened 1 year ago

Kalkwst commented 1 year ago

A splay tree is a type of self-balancing binary search tree, which is used to efficiently store and retrieve data. It is different from other types of self-balancing trees in that it adjusts the tree based on the usage patterns of the data, rather than by maintaining a specific balance condition. This can lead to improved performance of search and insertion operations, especially when the tree is being used to store data that is accessed frequently.

From a more technical perspective, a splay tree is a self-balancing binary search tree that uses a series of rotations to adjust the tree based on usage patterns. When a node is accessed, it is moved to the root of the tree, and the tree is adjusted accordingly to keep the most frequently accessed nodes closer to the root. This can improve the performance of search and insertion operations, as the nodes that are accessed most frequently are closer to the root and can be accessed faster. The time complexity for search and insertion operations in a splay tree is O(log n) on average, but it can be as fast as O(1) if the accessed node is already in the tree and it's near the root. However, it can be as slow as O(n) if the tree is unbalanced and all nodes are accessed in sequential order.