Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f5a9ede
fix(c): support negative values in radix sort
notzenco Oct 23, 2026
68b0fd9
test(c): add randomized BST model test
notzenco Oct 23, 2026
ccc4d4c
build(c): track header dependencies in the Makefile
notzenco Oct 23, 2026
7427e59
style(go): apply gofmt
notzenco Oct 23, 2026
f7746c7
fix(go): accept the full int range in counting and radix sort
notzenco Oct 23, 2026
4002b5f
fix(go): correct interpolation search, B-tree, and empty patterns
notzenco Oct 23, 2026
2187816
fix(go): keep repeated values once in BSTFromSortedSlice
notzenco Oct 23, 2026
a10f309
test(go): add fuzz targets and fill coverage gaps
notzenco Oct 23, 2026
8921fb5
fix(java): accept negative values in radix and counting sort
notzenco Oct 23, 2026
8138b0c
fix(java)!: keep binary search tree keys unique
notzenco Oct 23, 2026
f2f5ddc
fix(python): repair diagram docstring escapes
notzenco Oct 23, 2026
9cef648
fix(python)!: keep binary search tree keys unique
notzenco Oct 23, 2026
b1806ca
fix(python): store explicit None values in AVL trees
notzenco Oct 23, 2026
12ddb61
fix(python)!: unify LFU caches and keep minimum frequency current
notzenco Oct 23, 2026
19a89c3
test(python): add model tests and fail on warnings
notzenco Oct 23, 2026
5790f9f
refactor(rust): resolve clippy and rustdoc warnings
notzenco Oct 23, 2026
0d772c1
fix(rust): bound counting sort ranges
notzenco Oct 23, 2026
dee3fe9
test(rust): add fixed-seed model tests
notzenco Oct 23, 2026
06ac6ca
chore(rust): fix repository URL and TTL claim in crate docs
notzenco Oct 23, 2026
fb9d646
fix(typescript): accept every safe integer in counting and radix sort
notzenco Oct 23, 2026
5e4d8de
fix(typescript)!: keep binary search tree keys unique
notzenco Oct 23, 2026
57a84f2
build(typescript): add typecheck script and pin type packages
notzenco Oct 23, 2026
4a7ec1e
test(typescript): add model tests and close coverage gaps
notzenco Oct 23, 2026
b8529f1
ci: enforce lints, sanitizers, typecheck, and minimum versions
notzenco Oct 23, 2026
5a3324d
chore(hooks): make hooks executable and check every language
notzenco Oct 23, 2026
c2c02a2
docs: align README, topic pages, and remediation notes
notzenco Oct 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .githooks/commit-msg
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ NC='\033[0m'
# Valid prefixes (conventional commits)
valid_prefixes="feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert"

# Pattern: prefix(optional-scope): description
pattern="^($valid_prefixes)(\(.+\))?: .+"
# Pattern: prefix(optional-scope)(optional !): description
pattern="^($valid_prefixes)(\([^)]+\))?!?: .+"

if ! echo "$commit_msg" | head -1 | grep -qE "$pattern"; then
echo -e "${RED}Invalid commit message format!${NC}"
echo ""
echo "Commit message must follow: <type>(<scope>): <description>"
echo "Add ! before the colon for a breaking change: <type>(<scope>)!: <description>"
echo ""
echo -e "${YELLOW}Valid prefixes:${NC}"
echo " feat: New feature"
Expand All @@ -39,6 +40,7 @@ if ! echo "$commit_msg" | head -1 | grep -qE "$pattern"; then
echo " fix(rust): resolve memory leak in linked list"
echo " docs: update README with examples"
echo " test(python): add edge case tests for sorting"
echo " feat(c)!: require path capacity in shortest_path_reconstruct"
echo ""
echo -e "Your message: ${RED}$commit_msg${NC}"
exit 1
Expand Down
Empty file modified .githooks/install.sh
100644 → 100755
Empty file.
20 changes: 18 additions & 2 deletions .githooks/pre-commit
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,26 @@ if command -v cargo &> /dev/null; then
fi

echo -n "Running Rust clippy... "
if (cd by-language/rust && cargo clippy --all-targets -- -D warnings) &> /dev/null 2>&1; then
if (cd by-language/rust && cargo clippy --workspace --all-targets --all-features -- -D warnings) &> /dev/null; then
echo -e "${GREEN}OK${NC}"
else
echo -e "${RED}WARNINGS${NC} (continuing)"
echo -e "${RED}FAILED${NC}"
echo "Run 'cd by-language/rust && cargo clippy --workspace --all-targets --all-features -- -D warnings' for details"
FAILED=1
fi
fi

# Go checks
if command -v gofmt &> /dev/null; then
echo -n "Checking Go formatting... "
unformatted=$(cd by-language/go && gofmt -l .)
if [ -z "$unformatted" ]; then
echo -e "${GREEN}OK${NC}"
else
echo -e "${RED}FAILED${NC}"
echo "$unformatted"
echo "Run 'cd by-language/go && gofmt -w .' to fix"
FAILED=1
fi
fi

Expand Down
35 changes: 34 additions & 1 deletion .githooks/pre-push
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ FAILED=0
# Rust tests
if command -v cargo &> /dev/null; then
echo -e "\n${YELLOW}Running Rust tests...${NC}"
if (cd by-language/rust && cargo test --all-features); then
if (cd by-language/rust && cargo test --workspace --all-features); then
echo -e "${GREEN}Rust tests passed!${NC}"
else
echo -e "${RED}Rust tests failed!${NC}"
Expand Down Expand Up @@ -46,6 +46,39 @@ if command -v make &> /dev/null && [ -f "by-language/c/Makefile" ]; then
fi
fi

# Go tests
if command -v go &> /dev/null; then
echo -e "\n${YELLOW}Running Go tests...${NC}"
if (cd by-language/go && go vet ./... && go test ./...); then
echo -e "${GREEN}Go tests passed!${NC}"
else
echo -e "${RED}Go tests failed!${NC}"
FAILED=1
fi
fi

# TypeScript tests
if command -v bun &> /dev/null; then
echo -e "\n${YELLOW}Running TypeScript tests...${NC}"
if (cd by-language/typescript && bun install --frozen-lockfile && bun run typecheck && bun test); then
echo -e "${GREEN}TypeScript tests passed!${NC}"
else
echo -e "${RED}TypeScript tests failed!${NC}"
FAILED=1
fi
fi

# Java tests (macOS ships a java stub without a runtime, so probe it)
if java -version &> /dev/null; then
echo -e "\n${YELLOW}Running Java tests...${NC}"
if (cd by-language/java && ./gradlew test); then
echo -e "${GREEN}Java tests passed!${NC}"
else
echo -e "${RED}Java tests failed!${NC}"
FAILED=1
fi
fi

if [ $FAILED -eq 1 ]; then
echo -e "\n${RED}Pre-push tests failed. Push aborted.${NC}"
exit 1
Expand Down
73 changes: 66 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']

steps:
- uses: actions/checkout@v4
Expand All @@ -26,6 +26,11 @@ jobs:
python -m pip install --upgrade pip
pip install pytest pytest-cov

- name: Check for invalid escape sequences
run: |
cd by-language/python
python -W error::SyntaxWarning -m compileall -q -f data_structures algorithms tests

- name: Run Python tests
run: |
cd by-language/python
Expand All @@ -47,6 +52,13 @@ jobs:
cd by-language/c
make test

- name: Run C tests with AddressSanitizer and UBSan
run: |
cd by-language/c
make -B test \
CFLAGS='-Wall -Wextra -std=c11 -g -O1 -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer -I.' \
LDFLAGS='-fsanitize=address,undefined'

rust-tests:
runs-on: ubuntu-latest

Expand All @@ -66,18 +78,44 @@ jobs:
- name: Run clippy
run: |
cd by-language/rust
cargo clippy --all-targets -- -W clippy::all
cargo clippy --workspace --all-targets --all-features -- -D warnings

- name: Run tests
run: |
cd by-language/rust
cargo test --all-features
cargo test --workspace --all-features

- name: Check no_std build
run: |
cd by-language/rust
cargo check --workspace --no-default-features

- name: Check documentation
env:
RUSTDOCFLAGS: -D warnings
run: |
cd by-language/rust
cargo doc --workspace --no-deps

rust-msrv:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Rust 1.70 (declared rust-version)
uses: dtolnay/rust-toolchain@1.70

- name: Check library crates
run: |
cd by-language/rust
cargo check -p dsa-core -p dsa-data-structures -p dsa-algorithms --lib

go-tests:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.21', '1.22']
go-version: ['1.21', 'stable']

steps:
- uses: actions/checkout@v4
Expand All @@ -87,10 +125,26 @@ jobs:
with:
go-version: ${{ matrix.go-version }}

- name: Check formatting
if: matrix.go-version == 'stable'
run: |
cd by-language/go
unformatted=$(gofmt -l .)
if [ -n "$unformatted" ]; then
echo "Files need gofmt:"
echo "$unformatted"
exit 1
fi

- name: Run go vet
run: |
cd by-language/go
go vet ./...

- name: Run Go tests
run: |
cd by-language/go
go test ./...
go test -race ./...

typescript-tests:
runs-on: ubuntu-latest
Expand All @@ -104,7 +158,12 @@ jobs:
- name: Install dependencies
run: |
cd by-language/typescript
bun install
bun install --frozen-lockfile

- name: Type-check
run: |
cd by-language/typescript
bun run typecheck

- name: Run TypeScript tests
run: |
Expand Down Expand Up @@ -132,4 +191,4 @@ jobs:
- name: Run Java tests
run: |
cd by-language/java
gradle test
./gradlew test
43 changes: 31 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

A comprehensive collection of data structures and algorithms implemented in **C**, **Go**, **Java**, **Python**, **Rust**, and **TypeScript**.

Each implementation includes:
- Detailed ASCII visual diagrams
- Time & space complexity analysis
- LeetCode problem mappings
- Comprehensive unit tests
Every language has:
- Unit tests for each data structure and algorithm
- Seeded randomized tests that compare implementations against simple reference models
- Time & space complexity notes

Most C, Python, and Rust sources also include ASCII diagrams and LeetCode problem
mappings in their header comments. The Go, Java, and TypeScript sources use shorter
doc comments.

## Language Requirements

Expand Down Expand Up @@ -58,8 +61,8 @@ dsa/
| Stack | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Queue | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Deque | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Circular Queue | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Min/Max Stack | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Circular Queue | ✓ | ✓ | ✓ | ✓ | - | ✓ |
| Min/Max Stack | ✓ | ✓ | ✓ | ✓ | - | ✓ |
| Monotonic Queue | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |

### Trees
Expand Down Expand Up @@ -89,7 +92,7 @@ dsa/
| Structure | C | Go | Java | Python | Rust | TypeScript |
|-----------|:-:|:--:|:----:|:------:|:----:|:----------:|
| Adjacency List | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Adjacency Matrix | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Adjacency Matrix | ✓ | ✓ | ✓ | ✓ | - | ✓ |
| Union-Find | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |

### Caches
Expand Down Expand Up @@ -122,7 +125,7 @@ dsa/
| Algorithm | C | Go | Java | Python | Rust | TypeScript |
|-----------|:-:|:--:|:----:|:------:|:----:|:----------:|
| Binary Search | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Two Pointers | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Two Pointers | ✓ | ✓ | ✓ | ✓ | ✓ | - |
| Sliding Window | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |

### Graph
Expand All @@ -136,7 +139,8 @@ dsa/
| Prim's MST | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Kruskal's MST | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Topological Sort | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Tarjan's SCC | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Tarjan's SCC | ✓ | ✓ | ✓ | ✓ | - | ✓ |
| Kosaraju's SCC | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |

### Dynamic Programming
| Problem | C | Go | Java | Python | Rust | TypeScript |
Expand All @@ -155,6 +159,16 @@ dsa/
| Rabin-Karp | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Z-Algorithm | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |

### Go-only modules
The Go implementation also has algorithm modules that the other languages do not
have yet:

| Module | Contents |
|--------|----------|
| Backtracking | Permutations, subsets, combinations, combination sum, N-Queens, Sudoku, word search, generate parentheses |
| Greedy | Activity selection, interval problems, fractional knapsack, job sequencing, Huffman encoding, jump game, gas station, task scheduler |
| Math | GCD/LCM, primality and sieve, prime factors, fast power, Euler's totient, modular inverse, binomial and Catalan numbers, bit tricks |

## Quick Start

### C
Expand Down Expand Up @@ -192,6 +206,7 @@ cargo test
```bash
cd by-language/typescript
bun install
bun run typecheck
bun test
```

Expand All @@ -205,13 +220,17 @@ APIs should update their arguments before using the revised implementations.

### Git Hooks (Optional)
```bash
# Install pre-commit and pre-push hooks
# Install pre-commit, pre-push, and commit-msg hooks
./.githooks/install.sh
```

The pre-commit hook checks Rust formatting and Clippy, Go formatting, and Python
lint when `ruff` or `black` is installed. The pre-push hook runs the suite for
each language whose toolchain is installed.

## Implementation Template

Each implementation follows a consistent format:
The C, Python, and Rust header comments follow this format:

```
/**
Expand Down
Loading
Loading