Skip to main content

AVL Tree Practice Tool

A terminal-based interactive learning tool to practice AVL tree insertions, deletions, and rotations. This CLI (Command Line Interface) allows you to explore self-balancing binary search trees with visual feedback and two learning modes: automatic and practice.

Features

  • 📈 AVL Tree Visualization: Displays the tree in a clear grid layout with connectors.
  • 🤖 Automatic Mode: Automatically balances the tree after insertions/deletions.
  • 🧠 Practice Mode: Learn AVL balancing by manually applying the correct rotations.
  • 📚 Step-by-Step Guidance: See every rotation explained and shown.
  • ⚡ Multiple Commands: Chain multiple commands in a single line (e.g., a 10 a 20 a 30).
  • 🔄 Tree Traversals: View preorder, inorder, and postorder traversals.
  • 🎨 Color-Coded Display:
    • bright_green for recently added nodes
    • red for unbalanced nodes

Installation

pipx install avltreecli

Make sure you have Python 3.13 installed.

Usage

avltreecli

Commands

Command Description
a <value> Add a node (values: -99 to 999)
d <value> Remove a node
rl <value> Left rotation (shortcut)
rr <value> Right rotation (shortcut)
tree Display current AVL tree
reset Clear the tree
status Show current configuration and tree stats
hint Show hints for how to balance the tree
preorder Show preorder traversal
inorder Show inorder traversal
postorder Show postorder traversal
clear Clear screen and show current state
help Display help information
exit Exit the program

Multiple Commands

You can chain multiple commands in a single line for faster operations:

# Add multiple nodes at once
> a 10 a 20 a 30 a 40 a 50

# Mix operations
> a 15 a 25 d 20 a 35

# Quick tree building
> a 50 a 30 a 70 a 20 a 40 a 60 a 80

Configuration

You can change runtime settings with:

config <setting> <value>

Available settings:

Setting Values Description
autoshow on / off Automatically display tree after actions
steps on / off Show step-by-step balancing actions
mode automatic / practice Switch between learning and auto-balance

Modes

  • 🟢 Automatic Mode (default):
    The AVL tree balances itself automatically after every operation. Rotate commands are disabled.

  • 🟡 Practice Mode:
    Balance the tree manually with guided hints and validation. Only correct rotations are allowed.

Example Session

# Basic operations
> a 30
Added 30 to the tree

> a 20
Added 20 to the tree

> a 10
Tree is unbalanced! Node 30 has balance factor 2
Step 1: Balancing node 30 (balance: 2)
→ Performing right rotation on node 30
Tree is now balanced!

# Multiple commands in one line
> a 40 a 50 a 60
Added 40 to the tree
Added 50 to the tree
Tree is unbalanced! Node 40 has balance factor -2
Step 1: Balancing node 40 (balance: -2)
→ Performing left rotation on node 40
Added 60 to the tree

# View tree structure
> tree
+---+---+---+---+---+---+---+
|   |   |   | 30|   |   |   |
+---+---+---+---+---+---+---+
|   | 20| < | ╩ | > | 50|   |
+---+---+---+---+---+---+---+
| 10|   |   |   | 40| ╩ | 60|
+---+---+---+---+---+---+---+

# Check traversals
> inorder
Inorder traversal: 10 -> 20 -> 30 -> 40 -> 50 -> 60

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

License

This project is licensed under the MIT License.

Metadata

Release files for avltreecli 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for avltreecli 0.2.0
File Size Uploaded Provenance Actions
avltreecli-0.2.0.tar.gz 15.9 kB Without provenance Details for avltreecli-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for avltreecli 0.2.0
File Interpreter ABI Platform Actions
avltreecli-0.2.0-py3-none-any.whl Python 3 none any Details for avltreecli-0.2.0-py3-none-any.whl

Total release size: 32.1 kB

Release files / avltreecli-0.2.0.tar.gz

Download URL avltreecli-0.2.0.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9ed013686ef631b80c96c2de7996dc4453e4b1f9770d51c25e347cc7a325cbe7
BLAKE2b-256 checksum
How to use checksums
9d33221d357ee78f189d375037776020ad13808a21fcad7d8e0edef624988ce2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.13.3 Darwin/24.5.0

Release files / avltreecli-0.2.0-py3-none-any.whl

Download URL avltreecli-0.2.0-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ff004fbd8fd2dd3a4eebd17caab4e64c9afe1193255fa6f6284d74d5f92850f
BLAKE2b-256 checksum
How to use checksums
aa50dcc28791a639bf39d515bbab0c3bfa02ab79ab11ca8868563d4aaaf9e7a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.13.3 Darwin/24.5.0

Security for avltreecli 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page