data-structure-selector
npx machina-cli add skill a5c-ai/babysitter/data-structure-selector --openclawData Structure Selector Skill
Purpose
Select the optimal data structure based on required operations, their frequencies, and time/space constraints.
Capabilities
- Analyze required operations (insert, delete, query, update)
- Match to optimal data structure
- Consider time/space trade-offs
- Suggest augmentations for custom requirements
- Compare alternatives with complexity analysis
Target Processes
- data-structure-implementation
- algorithm-implementation
- complexity-optimization
Selection Framework
Operation Analysis
- What operations are needed?
- What are the frequency/priority of each operation?
- What are the constraints (N, Q, time limit)?
- Is persistence needed?
- Are range operations required?
Common Selection Patterns
| Operations | Best Choice |
|---|---|
| Insert, Delete, Search | BST / Hash Map |
| Range sum, Point update | Fenwick Tree |
| Range query, Range update | Segment Tree + Lazy |
| Union, Find | DSU |
| Min/Max with add/remove | Multiset / Heap |
| Predecessor/Successor | Ordered Set / BST |
Input Schema
{
"type": "object",
"properties": {
"operations": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"frequency": { "type": "string" },
"constraints": { "type": "string" }
}
}
},
"constraints": { "type": "object" },
"preferences": { "type": "array" }
},
"required": ["operations"]
}
Output Schema
{
"type": "object",
"properties": {
"success": { "type": "boolean" },
"recommended": { "type": "string" },
"complexities": { "type": "object" },
"alternatives": { "type": "array" },
"augmentations": { "type": "array" },
"reasoning": { "type": "string" }
},
"required": ["success", "recommended"]
}
Source
git clone https://github.com/a5c-ai/babysitter/blob/main/plugins/babysitter/skills/babysit/process/specializations/algorithms-optimization/skills/data-structure-selector/SKILL.mdView on GitHub Overview
The Data Structure Selector analyzes required operations (insert, delete, query, update) and their frequencies, plus time and space constraints, to identify the optimal structure. It maps operation profiles to proven choices (BSTs, hash maps, Fenwick trees, segment trees, DSU, multisets, and heaps) and surfaces trade-offs and augmentations for custom requirements.
How This Skill Works
It takes an operation profile, constraint context, and optional persistence needs, then applies the selection framework outlined in the skill. Using patterns like Insert/Delete/Search mapping to BST/Hash Map and specialized structures for range operations, it recommends a candidate data structure and provides a complexity comparison and augmentation ideas.
When to Use It
- When you need fast inserts and lookups with variable data sizes, consider BSTs or hash maps.
- When range queries or updates dominate (e.g., prefix sums or interval queries), use Fenwick Tree or Segment Tree + Lazy.
- When unions and finds are central, DSU is the best fit.
- When you require accurate min/max with dynamic adds/removes, use Multiset or Heap.
- When predecessor or successor queries are frequent, consider an Ordered Set or BST.
Quick Start
- Step 1: Gather the operations, frequencies, constraints, and persistence needs.
- Step 2: Run the selection analysis to map to a candidate structure.
- Step 3: Review the recommended structure, note any augmentations, and implement.
Best Practices
- Quantify operation frequencies and latency/throughput goals before selecting a structure.
- Explicitly note persistence, range requirements, and update patterns.
- Compare alternatives using asymptotic complexity and practical benchmarks.
- Document any proposed augmentations or custom constraints.
- Validate the choice with workload simulations on representative data sizes.
Example Use Cases
- Inventory systems: frequent add/remove and fast lookups leverage a hash map.
- Real-time dashboards performing range sums and updates use Fenwick Tree.
- Timeline analysis with range queries uses Segment Tree with lazy propagation.
- Graph clustering uses DSU for union/find operations.
- Task scheduling with dynamic priority uses a heap-based multiset.