An educational Python package for learning algorithms through step-by-step tracking and visualization
Project description
algo_learn - Educational Algorithm Learning Package
๐ Overview
algo_learn is an educational Python package designed to help students understand classic algorithms and machine learning techniques through step-by-step tracking, visualization, and a lightweight conversational interface.
This package was developed as part of an undergraduate computer science education project. The code prioritizes pedagogical clarity over production optimizations, making it ideal for:
- Learning algorithm internals
- Creating visualizations and animations
- Understanding ML training dynamics
- Academic submissions and coursework
โจ Features
Core Algorithms (From Scratch)
- Sorting: Bubble Sort, Merge Sort, Quick Sort
- Searching: Linear Search, Binary Search
- Graph Algorithms: BFS, Dijkstra's Shortest Path
- Dynamic Programming: Fibonacci, 0/1 Knapsack
- String Algorithms: KMP Pattern Matching
Machine Learning (No scikit-learn!)
- Supervised: Linear Regression, Logistic Regression, K-Nearest Neighbors
- Unsupervised: K-Means Clustering, PCA (via SVD)
Educational Tools
- Step Tracking: Every algorithm supports
track=Truemode returning intermediate states - Visualization: Decoupled plotting module for animations and heatmaps
- Benchmark Utilities: Timing and operation counting with log-log plots
- Chat UI: Natural language interface for algorithm interaction
๐ Installation
# Install from PyPI (when published)
pip install algo_learn
# Or install from source
git clone https://github.com/yourusername/algo_learn.git
cd algo_learn
pip install -e .
Development Dependencies
pip install -e ".[dev]"
๐ Quick Start
Basic Usage
from algo_learn.sorting import merge_sort
from algo_learn.ml_supervised import LinearRegression
import numpy as np
# Sorting with step tracking
arr = [5, 2, 8, 1, 9]
result, state_log = merge_sort(arr, track=True)
print(f"Sorted: {result}")
print(f"Steps tracked: {len(state_log)}")
# Machine Learning with tracking
X = np.random.randn(100, 3)
y = np.random.randn(100)
model = LinearRegression()
model.fit(X, y, track=True)
predictions = model.predict(X)
Visualization
from algo_learn.visualizer import plot_sorting_animation, plot_loss_curve
# Create sorting animation
plot_sorting_animation(state_log, save_path="sorting_demo.gif")
# Plot ML training loss
plot_loss_curve(model.state_log_, title="Linear Regression Training")
Chat Interface
from algo_learn.chat_ui import ChatUI
chat = ChatUI()
chat.run()
# Example commands:
# "sort [5,2,8] with merge and show steps"
# "explain why quicksort degrades"
# "run k-means on moons data"
๐ Project Structure
algo_learn/
โโโ pyproject.toml # Package configuration
โโโ README.md # This file
โโโ src/
โ โโโ algo_learn/
โ โโโ __init__.py # Public API exports
โ โโโ step_logger.py # Central state manager
โ โโโ visualizer.py # Matplotlib visualizations
โ โโโ dataset_gen.py # Synthetic data generation
โ โโโ benchmark.py # Timing and profiling
โ โโโ sorting.py # Sorting algorithms
โ โโโ searching.py # Search algorithms
โ โโโ graphs.py # Graph algorithms
โ โโโ dynamic_programming.py # DP algorithms
โ โโโ string_algos.py # String algorithms
โ โโโ ml_supervised.py # Supervised ML
โ โโโ ml_unsupervised.py # Unsupervised ML
โ โโโ chat_ui.py # Conversational interface
โโโ examples/
โ โโโ demo_notebook.ipynb # Jupyter notebook examples
โโโ tests/
โโโ test_tracking.py # Unit tests
๐ฏ API Design
All algorithms follow a consistent API pattern:
# Classic algorithms
result, state_log = algorithm_name(data, track=False)
# ML estimators
model = AlgorithmName()
model.fit(X, y, track=False) # Sets model.state_log_ if track=True
predictions = model.predict(X)
State Log Format
When track=True, algorithms return a list of dictionaries or pandas DataFrame with columns like:
step: Iteration numberarray_state: Current array/list statecomparisons: Number of comparisons madevisited: Nodes/elements visitedloss: Training loss (for ML algorithms)
๐งช Testing
pytest tests/
๐ Academic Submission Notes
This package was developed following these principles:
- Educational Transparency: Code favors explicit loops and temporary variables over clever one-liners
- Pedagogical Comments: Line-by-line explanations of algorithmic intent
- No Black Boxes: All algorithms implemented from scratch using only numpy, pandas, matplotlib
- Reproducible Results: Deterministic behavior with optional random seeds
- Jupyter-Ready: All outputs compatible with
%matplotlib inline
Citation
If you use this package in academic work:
@software{algo_learn2024,
title = {algo\_learn: Educational Algorithm Learning Package},
author = {Student Developer},
year = {2024},
url = {https://github.com/yourusername/algo_learn}
}
๐ง Dependencies
numpy>=1.20.0- Numerical computingpandas>=1.3.0- Data structures and loggingmatplotlib>=3.4.0- Visualization
๐ License
MIT License - See LICENSE file for details.
๐ค Contributing
Contributions welcome! This is an educational project, so please prioritize:
- Clear, commented code
- Pedagogical value
- Test coverage for tracking functionality
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 algo_learn-0.1.0.tar.gz.
File metadata
- Download URL: algo_learn-0.1.0.tar.gz
- Upload date:
- Size: 41.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
faaffb5b7188273ad470f9616ec9935d53d43f71f0b9a9a0aaa50f573691c289
|
|
| MD5 |
d7346fc73d953c59c79dce2d43cfd295
|
|
| BLAKE2b-256 |
9bafce46e708f39bf3b7e69a0618aa14b8ef32276ecaf44945f76a4e8cd36e7f
|
File details
Details for the file algo_learn-0.1.0-py3-none-any.whl.
File metadata
- Download URL: algo_learn-0.1.0-py3-none-any.whl
- Upload date:
- Size: 44.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c406577f132c12d1a1d6cbe902fc1e2e47bd74d1b54ad9c493b8b44fbdc7f17
|
|
| MD5 |
b9423abac8e2b2da96376e4f5e516149
|
|
| BLAKE2b-256 |
8bf95b2c6c85bd29f7f6b45015d0e2f4f61b1ad91890ded7ad11ba2b5cc5051d
|