Claude
Skills
Sign in
Back

cs-data-structures

Included with Lifetime
$97 forever

Data structures: arrays, linked lists, trees BST/AVL/B-tree, heaps, hash tables, graphs, tries

Generaldata-structurestreesgraphshashcs

What this skill does


# cs-data-structures

## Purpose
This skill equips the OpenClaw AI to generate, manipulate, and optimize code for core data structures, including arrays, linked lists, trees (BST, AVL, B-tree), heaps, hash tables, graphs, and tries, to solve programming tasks efficiently.

## When to Use
Use this skill when implementing data storage or manipulation in code, such as sorting large datasets with arrays, searching nodes in a BST, or traversing graphs for pathfinding. Apply it in scenarios requiring efficient operations like O(1) lookups in hash tables or balanced trees for sorted data.

## Key Capabilities
- Arrays: Support creation, sorting (e.g., quicksort, mergesort), and searching (e.g., binary search).
- Linked Lists: Handle singly/doubly linked lists with operations like insertion, deletion, and traversal.
- Trees: Implement BST for basic searches, AVL for self-balancing, B-tree for disk-based storage; include traversals (in-order, pre-order).
- Heaps: Manage min/max heaps for priority queues, with heapify and extract operations.
- Hash Tables: Provide hashing functions, collision resolution (chaining/open addressing), and key-value operations.
- Graphs: Support adjacency lists/matrices, BFS, DFS, shortest paths (e.g., Dijkstra), and cycle detection.
- Tries: Enable prefix-based string storage and search for autocomplete features.

## Usage Patterns
To invoke this skill, prefix commands with `openclaw ds <structure> <action>`. Always specify the structure type and action parameters for precision. For code integration, import the generated module and call functions directly. Use in a pipeline: first generate code with a command, then test it in your environment. If using in a script, set the context with `--context=project-file.py` to embed the code snippet. For repeated use, save outputs to a config file like JSON: {"structure": "bst", "action": "insert", "params": {"value": 5}}.

## Common Commands/API
Use the OpenClaw CLI for direct execution. Commands require authentication via the environment variable `$OPENCLAW_API_KEY`. Example CLI flags:
- `openclaw ds array create --size=10 --init=[1,2,3,4]` to generate an array initialization snippet.
- `openclaw ds tree bst insert --node=5 --root=var_root` to add a node to a BST (output: 2-3 lines of code).
- `openclaw ds graph bfs --vertices=5 --edges='[[0,1],[1,2]]'` for BFS traversal code.
For API integration, send HTTP requests to endpoints like POST /api/ds/{structure} with a JSON body, e.g., {"action": "sort", "params": {"array": [4,2,1], "algorithm": "quicksort"}}. Code snippets:
```python
# Example for hash table insertion
hash_table = {}  # Generated by openclaw ds hash create
hash_table['key'] = 'value'  # Use openclaw ds hash insert --key='key' --value='value'
```
```python
# Example for linked list traversal
node = head  # From openclaw ds linkedlist create
while node:  # Traverse using openclaw ds linkedlist traverse
    print(node.data)
    node = node.next
```

## Integration Notes
Integrate this skill into your codebase by generating snippets and importing them as modules. For authentication, set `$OPENCLAW_API_KEY` in your environment before running commands, e.g., export OPENCLAW_API_KEY=your_api_key. Use config files in YAML format for multi-step operations: structure: bst, actions: [insert, search]. Chain with other OpenClaw skills by piping outputs, e.g., `openclaw ds graph create | openclaw cs-algorithms bfs`. Ensure your project uses compatible languages like Python or C++ by specifying `--lang=python`.

## Error Handling
Always validate inputs before commands, e.g., check if structure types are valid (use `openclaw ds list` to query available structures). Common errors include invalid parameters (e.g., negative array size), handled by returning error codes like 400 with messages: "Error: Array size must be positive." In code snippets, wrap operations in try-except blocks, e.g.:
```python
try:
    result = bst.search(5)  # From openclaw ds tree bst search
except KeyError:
    print("Node not found")
```
For API calls, check HTTP status codes and parse error responses. Retry transient errors with exponential backoff if API rate-limited.

## Graph Relationships
- Related to: cs-algorithms (for algorithms operating on these structures, e.g., sorting arrays or traversing graphs).
- Connected to: software-engineering (for best practices in implementing data structures in production code).
- Links to: cs-networks (for graph applications in network topology).
- Associated with: ai-tools (for embedding hints like data structure queries in AI prompts).

Related in General