algocode
Call an algorithm by name and get its source code, a plain-English explanation, its time/space complexity, and an optional step-by-step trace on your own data.
Built for competitive programming and learning: grab a clean, ready-to-paste implementation in seconds, or watch exactly how an algorithm behaves on a specific input.
---
Installation
Install from PyPI with pip:
pip install algocode
To upgrade to the latest version later:
pip install --upgrade algocode
Requires Python 3.8 or newer. No external dependencies.
---
Quick start
import algocode as ac
algo = ac.get("quicksort")
print(algo.code()) # source code as a ready-to-paste string
print(algo.explain()) # summary + complexity + stability
algo.trace(\[2, 4, 6, 8, 1, 3, 5]) # prints the step-by-step run
ac.available() # list every algorithm name
The pattern is always the same: ac.get("name") to fetch an algorithm, then call .code(), .explain(), or .trace() on it.
---
What you can call
Two top-level functions:
| Call | What it does |
|---|---|
ac.available() |
Returns a sorted list of every algorithm name. |
ac.get("name") |
Returns an algorithm object (accepts aliases like "quick", "binary"). |
Methods on the object returned by ac.get(...):
| Method | What it returns |
|---|---|
.code() |
The source code as a string, ready to copy-paste. |
.code(\[your, data]) |
The same source plus a runnable usage line filled in with your data. |
.explain() |
Summary of how it works, its best/average/worst time, space, and whether it's stable. |
.trace(\[your, data]) |
Prints a step-by-step walkthrough on your data, and returns the steps as a list. |
---
Available algorithms
Currently 9 algorithms, grouped by category.
Sorting
| Name | Idea | Time (best / avg / worst) | Space | Stable |
|---|---|---|---|---|
quicksort |
Divide & conquer around a pivot | O(n log n) / O(n log n) / O(n²) | O(log n) | no |
mergesort |
Split in half, sort, merge | O(n log n) / O(n log n) / O(n log n) | O(n) | yes |
bubblesort |
Swap adjacent out-of-order pairs | O(n) / O(n²) / O(n²) | O(1) | yes |
insertionsort |
Insert each element into the sorted left part | O(n) / O(n²) / O(n²) | O(1) | yes |
selectionsort |
Repeatedly grab the minimum | O(n²) / O(n²) / O(n²) | O(1) | no |
Searching
| Name | Idea | Time (best / avg / worst) | Space |
|---|---|---|---|
binarysearch |
Halve a sorted array each step | O(1) / O(log n) / O(log n) | O(1) |
linearsearch |
Scan left to right | O(1) / O(n) / O(n) | O(1) |
Math / utility
| Name | Idea | Time | Space |
|---|---|---|---|
gcd |
Euclid's algorithm for greatest common divisor | O(log(min(a, b))) | O(1) |
reverse |
Two-pointer in-place array reversal | O(n) | O(1) |
Get this list at any time with ac.available().
---
Aliases
Short names and common variants resolve to the right algorithm:
| You type | You get |
|---|---|
"quick", "quick\_sort" |
quicksort |
"merge", "merge\_sort" |
mergesort |
"bubble" |
bubblesort |
"insertion" |
insertionsort |
"selection" |
selectionsort |
"binary", "binary\_search" |
binarysearch |
"linear" |
linearsearch |
"hcf" |
gcd |
---
Examples
Get ready-to-run code for your data:
import algocode as ac
print(ac.get("quicksort").code(\[2, 4, 6, 8, 1, 3, 5]))
def quicksort(arr):
if len(arr) <= 1:
return arr
pivot = arr\[len(arr) // 2]
left = \[x for x in arr if x < pivot]
mid = \[x for x in arr if x == pivot]
right = \[x for x in arr if x > pivot]
return quicksort(left) + mid + quicksort(right)
# usage
print(quicksort(\[2, 4, 6, 8, 1, 3, 5]))
Watch it work step by step:
ac.get("bubblesort").trace(\[5, 1, 4, 2, 8])
Metadata
Release files for algocode 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| algocode-0.1.1.tar.gz | 7.3 kB | Without provenance | Details for algocode-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| algocode-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for algocode-0.1.1-py3-none-any.whl |
Total release size: 14.9 kB
Release files / algocode-0.1.1.tar.gz
| Download URL | algocode-0.1.1.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
420ecff0313702a97822ec5c35c81ab6e88af65105ddccd18529f50b6079078a
|
|
BLAKE2b-256 checksum How to use checksums |
fabcab7f7fdcc9365ef1100985c7872ae7278e71463bacd9f3a7d2104fc85539
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.0
|
Release files / algocode-0.1.1-py3-none-any.whl
| Download URL | algocode-0.1.1-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
09eba0d60f246e38a84dd1be6c9dd2bd002ea516eae7f7845059ba131a1d2417
|
|
BLAKE2b-256 checksum How to use checksums |
cecd422c249f161305c5fcb97fdbed1a7cdbf69e30237b950146c9d9050f31cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.0
|
Security for algocode 0.1.1
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.