feat: add self-balancing scapegoat tree implementation#3095
Open
OmarAhmedTHE25th wants to merge 4 commits intoTheAlgorithms:masterfrom
Open
feat: add self-balancing scapegoat tree implementation#3095OmarAhmedTHE25th wants to merge 4 commits intoTheAlgorithms:masterfrom
OmarAhmedTHE25th wants to merge 4 commits intoTheAlgorithms:masterfrom
Conversation
Contributor
|
This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Author
|
Hi! Just checking if any further changes are needed from my side. Happy to update if required. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
This PR adds a comprehensive implementation of a scapegoat tree, a self-balancing binary search tree. Unlike AVL or Red-Black trees, a scapegoat tree does not require extra storage (like height or color bits) per node, making it memory-efficient while still guaranteeing$O(\log n)$ amortized performance for basic operations.
Changes:
Self-Balancing Logic: Implemented find_traitor and restructure_subtree to handle α-weight balancing.
Modern C++
Features:
Added a custom iterator class for STL-compatible traversal.
Provided support for range-based for loops.
Advanced Queries: Added methods for kth_smallest, sum_in_range, and values_in_range.
Bulk Operations: Included insert_batch and delete_batch for efficient data handling.
Robust Testing: Included a comprehensive test suite in scapegoat_tests.cpp using assert() to verify tree properties and balancing after various operations.
Checklist
Notes:$O(\log n)$ operations, and α-weight balancing without per-node memory overhead.
A high-performance, self-balancing Scapegoat Tree implementation featuring STL-compatible iterators, amortized