feat: Segment Tree data structure in CPP#266
Merged
Pradeepsingh61 merged 1 commit intoPradeepsingh61:mainfrom Oct 2, 2025
Merged
feat: Segment Tree data structure in CPP#266Pradeepsingh61 merged 1 commit intoPradeepsingh61:mainfrom
Pradeepsingh61 merged 1 commit intoPradeepsingh61:mainfrom
Conversation
Signed-off-by: Arya Pratap Singh <notaryasingh@gmail.com>
|
🎉 Welcome to Hacktoberfest 2025, @ARYPROGRAMMER! 🎃 Thank you for your first contribution to our DSA repository! Here's what happens next: 🔍 Automatic Checks
📋 Next Steps🎯 Great job! Your code compiled successfully. Maintainers @Karanjot786 and @Pradeepsingh61 will review your PR soon. 🎁 What You Get
💡 Tips for Success
Welcome to the community! 🚀 |
🤖 Automated PR Status🔍 Code Validation✅ Passed - File naming and structure look good! 🧪 Compilation Tests✅ Passed - All code compiles successfully! 📋 Overall Status🎉 Ready for Review - Your PR has passed all automated checks! This comment was generated automatically. Checks will re-run when you push new commits. |
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.
Implements a complete Segment Tree data structure for efficient range queries and updates, filling a critical gap in the advanced data structures section.
Complete Segment Tree with O(log n) query/update operations
Three specialized implementations: Range Sum, Range Min, Range Max
Lazy propagation for efficient range updates
Point updates and range updates support
6 comprehensive demos covering all use cases
🎯 Key Features
✅ Range Sum Query with lazy propagation
✅ Range Minimum Query (RMQ)
✅ Range Maximum Query
✅ Point updates in O(log n)
✅ Range updates in O(log n) with lazy propagation
✅ Build in O(n), Space O(4n)
✅ Zero compiler warnings (-Wall -Wextra)
📊 Test Cases (6 Comprehensive Demos)
Range Sum Query with Point Updates - Basic sum queries and single element updates
Range Updates with Lazy Propagation - Efficient bulk updates across ranges
Range Minimum Query (RMQ) - Finding minimum in any range
Range Maximum Query - Finding maximum in any range
Performance Comparison - Segment Tree O(log n) vs Naive O(n)
Complex Scenario - Multiple mixed operations demonstrating real-world usage
🔧 Technical Details
Language: C++ (C++17 standard)
Time Complexity:
Build: O(n)
Range Query: O(log n)
Point Update: O(log n)
Range Update: O(log n) with lazy propagation
Space Complexity: O(4n)
Code Quality: Clean OOP design with three specialized classes, comprehensive documentation
🎓 Applications
Dynamic range queries in arrays
Computational geometry algorithms
Database query optimization
Competitive programming contests
String processing algorithms
Real-time statistics tracking
💡 Query Types Implemented
Range Sum Query - Total sum in any range with lazy propagation
Range Minimum Query - Minimum element in any range
Range Maximum Query - Maximum element in any range
📝 Follows Repository Standards
✅ Proper file naming (snake_case)
✅ Comprehensive header documentation
✅ Multiple test cases with edge cases
✅ Clean, readable code with comments
✅ No compilation errors or warnings
✅ Automatic demo execution (non-interactive)
🌟 Advantages Over Naive Approach
Speed: O(log n) queries vs O(n) naive approach
Updates: Efficient point and range updates
Versatile: Supports sum, min, max, and other aggregate queries
Space Efficient: Only O(4n) space required
Dynamic: Supports updates after construction
✨ Special Features
Lazy Propagation: Defers updates for O(log n) range modifications
Multiple Query Types: Three different segment trees for different needs
Error Handling: Validates ranges and indices
Performance Demo: Shows speed improvement over naive method