Skip to content

Conversation

@SamXop123
Copy link

Splay Tree Implementation

Description

This PR introduces a comprehensive implementation of a Splay Tree, a self-adjusting binary search tree with excellent performance characteristics for many use cases. The implementation includes all standard operations with proper splaying behavior.

Features

  • Core Operations: Insert, find, contains, remove
  • Tree Traversals: In-order, pre-order, post-order
  • Utility Methods: findMin, findMax, getHeight, isEmpty
  • Splaying Operations: zig, zig-zig, zig-zag rotations
  • Custom Comparators: Support for custom comparison functions
  • Comprehensive Test Coverage: 91.77% statement coverage, 85.63% branch coverage

Implementation Details

  • SplayTreeNode.js: Node class with rotation and splaying logic
  • SplayTree.js: Main tree class with public API
  • Test Files: 45+ test cases covering all functionality

Performance

  • Average Case: O(log n) for search, insert, and delete
  • Amortized Analysis: O(log n) per operation

Example Usage

const tree = new SplayTree();
tree.insert(10);
tree.insert(5);
tree.insert(15);
console.log(tree.contains(5)); // true
console.log(tree.findMin());  // 5
console.log(tree.findMax());  // 15

Checklist

  • Implement core functionality
  • Add comprehensive test cases
  • Add JSDoc comments
  • Update README with usage and documentation
  • Ensure proper error handling

Related Issues

Closes #271

- Implement SplayTreeNode class with splay operations (zig, zig-zig, zig-zag)
- Implement SplayTree class with insert, find, contains, remove operations
- Add comprehensive test coverage (45 tests total)
- Support custom comparators and various data types
- Handle edge cases and complex removal scenarios
- Achieve 91.77% statement coverage, 85.63% branch coverage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant