Skip to content

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.

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