TheAlgorithms / PHP

All Algorithms implemented in PHP
MIT License
2.14k stars 467 forks source link

Implemented Splay Tree Data Structure #168

Closed Ramy-Badr-Ahmed closed 1 month ago

Ramy-Badr-Ahmed commented 1 month ago

Description

A Splay Tree is a self-adjusting binary search tree that performs splaying, moving a specified element to the root of the tree through rotations. This allows frequently accessed elements to be accessed quickly, improving the performance of subsequent operations.

Applications

Contents

The SplayTreeRotations class facilitates the rotation operations needed to maintain the balance of the Splay Tree during node access and restructuring.

Unit Tests:

SplayTreeTest.php: Contains PHPUnit tests to validate the correct behavior of insertion, deletion, searching, updating, and ensuring the integrity of the Splay Tree structure. It also consider edge cases for these operations.

Time Complexity

The insert, delete, and search operations have an amortized time complexity of O(log n) in terms of tree height. The splay operation is also O(log n) on average.

GitHub Actions

All tests and workflows (in my forked repository) have passed.

Code style

directory_md

PHP Composer


Reference

Data Structures and Algorithms in C++, 2nd Edition

Ramy-Badr-Ahmed commented 1 month ago

Awesome work, as always. Thanks for adding this @Ramy-Badr-Ahmed !

Thanks, Brandon (@darwinz) 🙂

Ramy-Badr-Ahmed commented 1 month ago

EDIT:

PR is complemented with #171