Visualize algorithm execution to build intuition
Project description
🧠 AlgoViz — Algorithm Intuition Visualizer
See your algorithm think.
AlgoViz is a Python library that executes your algorithm and visualizes how it evolves step by step — pointer movement, recursion trees, sliding windows, dynamic programming state changes, AND generic function behavior patterns — all without print-debugging or heavyweight debuggers.
Perfect for:
- 📚 Learning algorithms
- 🎯 Interview prep (LeetCode-style)
- 👩🏫 Teaching & explanations
- 👀 Code reviews and intuition building
- 🔍 Understanding ANY function's behavior
Documentation
📖 See user documentation in docs/ directory
👨💻 See developer documentation in developer_doc/ directory
Quick Start for Users
- docs/project/CHANGELOG.md - Version history
- docs/project/CONTRIBUTING.md - How to contribute
For Developers & Contributors
- developer_doc/START_HERE.md (5 min) - Orientation
- developer_doc/architecture/ARCHITECTURE_DEEP_DIVE.md (40 min) - Complete system explanation
- developer_doc/getting-started/QUICK_START.md (10 min) - Practical examples
✨ Why AlgoViz?
| Tool | What it shows |
|---|---|
| Debugger | What happened |
| Profiler | How long it took |
| AlgoViz | Why it happened |
AlgoViz focuses on algorithmic patterns and state evolution, not just execution.
� Installation
pip install algo-viz
Requirements:
- Python 3.9+
- Zero external dependencies!
🚀 Quick Start
Example 1: Two Pointers Algorithm
from algo_viz import visualize
@visualize()
def two_sum(nums, target):
l, r = 0, len(nums) - 1
while l < r:
s = nums[l] + nums[r]
if s == target:
return l, r
elif s < target:
l += 1
else:
r -= 1
two_sum([1, 2, 3, 4, 5], 8)
Output:
[*] Detected patterns: Two Pointers
[*] Two Pointers Visualization
----------------------------------------------------------------------
Array: [1, 2, 3, 4, 5]
Step 1: [1] [2](l) [3] [4] [5](r)
l=1 r=4
Step 2: [1] [2] [3](l) [4] [5](r)
l=2 r=4
[*] Algorithm Trace
----------------------------------------
Step 02 | line 6 | l: 0 -> 1
Step 03 | line 8 | s: 6 -> 7
Step 04 | line 6 | l: 1 -> 2
Example 2: Dynamic Programming
from algo_viz import visualize
@visualize()
def climbing_stairs(n):
dp = [0] * (n + 1)
dp[0], dp[1] = 1, 1
for i in range(2, n + 1):
dp[i] = dp[i - 1] + dp[i - 2]
return dp[n]
climbing_stairs(5)
Output:
[*] Detected patterns: Dynamic Programming
[*] DP Table Evolution
--------------------------------------------------
Step 01 | Line 7 | dp[0] = 1
Step 02 | Line 7 | dp[1] = 1
Step 03 | Line 7 | dp[2] = dp[i - 1]=1 + dp[i - 2]=1 -> 2
Step 04 | Line 7 | dp[3] = dp[i - 1]=2 + dp[i - 2]=1 -> 3
Step 05 | Line 7 | dp[4] = dp[i - 1]=3 + dp[i - 2]=2 -> 5
Example 3: Recursion
from algo_viz import visualize
@visualize()
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n - 1) + fibonacci(n - 2)
fibonacci(4)
Output:
[*] Detected patterns: Recursion
[*] Recursion Tree
----------------------------------------
[+] fibonacci(n=4)
[+] fibonacci(n=3)
[+] fibonacci(n=2)
[+] fibonacci(n=1)
[-] return 1
[+] fibonacci(n=0)
[-] return 0
[-] return 1
...
🔍 Supported Patterns
✅ Dynamic Programming
- Automatically detects DP patterns
- Shows formula dependencies:
dp[i] = dp[i-1] + dp[i-2] - Visualizes DP table evolution
✅ Two Pointers
- Visualizes pointer positions in array
- Shows pointer movement step-by-step
- Marks current positions clearly
✅ Sliding Window
- Shows window boundaries
- Visualizes element inclusion/exclusion
- Tracks window size changes
✅ Recursion / DFS
- Call tree visualization
- Shows function arguments
- Tracks call depth and returns
🎨 Output Modes
ASCII (Default)
@visualize(mode="ascii")
def my_algorithm(data):
pass
Terminal-friendly output with step-by-step trace.
HTML
@visualize(mode="html")
def my_algorithm(data):
pass
Generates algo_viz.html with interactive timeline visualization.
🛠 API Reference
@visualize Decorator
@visualize(mode="ascii")
def algorithm(data):
"""Visualize algorithm execution"""
pass
Parameters:
mode(str): Output format -"ascii"(default) or"html"
Features:
- Zero configuration required
- Automatic pattern detection
- Works with any Python function
- No code modifications needed
📖 Documentation
AlgoViz now includes generic function analysis in addition to algorithm visualization:
- QUICK_START_GENERIC.md - Get started in 5 minutes
- GENERIC_ANALYSIS.md - Complete feature guide
- DEVELOPER_GENERIC.md - Extension & API reference
- UPGRADE_GUIDE.md - Backward compatibility info
⚙️ How It Works
AlgoViz uses Python's built-in sys.settrace() to:
- Trace function execution at the bytecode level
- Capture variable assignments and changes
- Detect algorithmic patterns automatically
- Extract formulas and dependencies
- Render step-by-step visualizations
No AST rewriting, no bytecode manipulation - pure runtime tracing!
🚀 Features
- ✅ Zero-configuration execution tracing
- ✅ Automatic algorithm pattern detection
- ✅ Step-by-step visualization
- ✅ ASCII and HTML renderers
- ✅ Python-native (runtime-based, no AST rewriting)
- ✅ Zero external dependencies
- ✅ Cross-platform (Windows, Linux, macOS)
- ✅ Works with LeetCode problems out of the box
🔧 Advanced Usage
Custom Visualization
Extend AlgoViz by importing pattern detectors:
from algo_viz.tracer.tracer import ExecutionTracer
from algo_viz.detectors.dp import detect_dp
def my_algorithm(data):
# your code
pass
tracer = ExecutionTracer()
result, events = tracer.run(my_algorithm, data)
if detect_dp(events):
print("DP pattern detected!")
📝 Examples
The examples/ directory contains ready-to-run demonstrations:
70_climbingStairs.py- Dynamic Programmingtwo_pointers.py- Two Pointer Technique50_fibonacci.py- RecursionlongestSubstringWithoutRepeatedCharacters.py- Sliding Window
Run any example:
python examples/70_climbingStairs.py
⚠️ Limitations
- Single-threaded algorithms only
- No support for generator functions
- Limited to algorithm-style code (not general-purpose debugging)
- Overhead is significant for performance-critical code
🤝 Contributing
Contributions are welcome! Areas for improvement:
- More algorithm pattern detectors
- Additional visualization formats
- Performance optimizations
- Documentation improvements
📄 License
MIT License - see LICENSE for details
🎓 Learning Resources
- Algorithm Visualizations - Complementary tool for understanding algorithms
- LeetCode - Practice problems
- GeeksforGeeks - Algorithm tutorials
💬 Feedback
Have ideas or found bugs? Open an issue on GitHub!
AlgoViz helps you:
- see pointer movement
- feel recursion
- understand state changes
If AlgoViz helped you, consider giving it a ⭐
⚠️ Notes
- Pattern detection is heuristic-based
- Visualization depends on executed inputs
- Designed for learning and intuition, not formal verification
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file algoviz_python-0.1.2.tar.gz.
File metadata
- Download URL: algoviz_python-0.1.2.tar.gz
- Upload date:
- Size: 25.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc4c94715d9fd23aa172d79a5f51479f26ffc327237819e28f417b26da1784db
|
|
| MD5 |
33e3f8ce469a054f0a0f2ccb64b17334
|
|
| BLAKE2b-256 |
ffb0c15d8ef585ebe669207d0f2df73f6664c710c1f4a1d1e827f8a5918c69fd
|
File details
Details for the file algoviz_python-0.1.2-py3-none-any.whl.
File metadata
- Download URL: algoviz_python-0.1.2-py3-none-any.whl
- Upload date:
- Size: 28.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c30956836fc826a1e9201e109dc06aeb1a5bce8a495f5fc706f3bf8ddf321f6
|
|
| MD5 |
5a95ee17e951bc6109f76f78de6cdb14
|
|
| BLAKE2b-256 |
a5b095bb3c85577a5f5b1d90952876d58881f356269e3fae3024b3c9483c90d6
|