Skip to main content

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=True mode 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 number
  • array_state: Current array/list state
  • comparisons: Number of comparisons made
  • visited: Nodes/elements visited
  • loss: Training loss (for ML algorithms)

๐Ÿงช Testing

pytest tests/

๐Ÿ“ Academic Submission Notes

This package was developed following these principles:

  1. Educational Transparency: Code favors explicit loops and temporary variables over clever one-liners
  2. Pedagogical Comments: Line-by-line explanations of algorithmic intent
  3. No Black Boxes: All algorithms implemented from scratch using only numpy, pandas, matplotlib
  4. Reproducible Results: Deterministic behavior with optional random seeds
  5. 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 computing
  • pandas>=1.3.0 - Data structures and logging
  • matplotlib>=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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

algo_learn-0.1.0.tar.gz (41.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

algo_learn-0.1.0-py3-none-any.whl (44.4 kB view details)

Uploaded Python 3

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

Hashes for algo_learn-0.1.0.tar.gz
Algorithm Hash digest
SHA256 faaffb5b7188273ad470f9616ec9935d53d43f71f0b9a9a0aaa50f573691c289
MD5 d7346fc73d953c59c79dce2d43cfd295
BLAKE2b-256 9bafce46e708f39bf3b7e69a0618aa14b8ef32276ecaf44945f76a4e8cd36e7f

See more details on using hashes here.

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

Hashes for algo_learn-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c406577f132c12d1a1d6cbe902fc1e2e47bd74d1b54ad9c493b8b44fbdc7f17
MD5 b9423abac8e2b2da96376e4f5e516149
BLAKE2b-256 8bf95b2c6c85bd29f7f6b45015d0e2f4f61b1ad91890ded7ad11ba2b5cc5051d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page