Skip to content

feat: add self-balancing scapegoat tree implementation#3095

Open
OmarAhmedTHE25th wants to merge 4 commits intoTheAlgorithms:masterfrom
OmarAhmedTHE25th:master
Open

feat: add self-balancing scapegoat tree implementation#3095
OmarAhmedTHE25th wants to merge 4 commits intoTheAlgorithms:masterfrom
OmarAhmedTHE25th:master

Conversation

@OmarAhmedTHE25th
Copy link

@OmarAhmedTHE25th OmarAhmedTHE25th commented Jan 15, 2026

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

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational - Doxygen guidelines
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes:
A high-performance, self-balancing Scapegoat Tree implementation featuring STL-compatible iterators, amortized $O(\log n)$ operations, and α-weight balancing without per-node memory overhead.

@github-actions
Copy link
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.

@github-actions github-actions bot added the stale Author has not responded to the comments for over 2 weeks label Feb 15, 2026
@OmarAhmedTHE25th
Copy link
Author

Hi! Just checking if any further changes are needed from my side. Happy to update if required. Thanks!

@github-actions github-actions bot removed the stale Author has not responded to the comments for over 2 weeks label Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant