Skip to content

Commit 23173e8

Browse files
committed
Document two-sum and benchmark workflow
1 parent b8f5904 commit 23173e8

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
# AlgoKit: Small Algorithm Practice
22

3-
A dependency-free collection of beginner-friendly algorithms with tests and clear input contracts.
3+
A dependency-free collection of beginner-friendly algorithms with unit and deterministic randomized tests.
44

55
## Run
66

77
```bash
88
python3 algokit.py
9-
python3 -m unittest -v
9+
python3 -m unittest discover -v
10+
python3 benchmark_search.py
1011
```
1112

12-
Run the commands from this directory. Python 3.8+ is recommended.
13+
Run these commands from this directory. Python 3.8+ is recommended.
1314

1415
## Included algorithms
1516

1617
| Function | Purpose | Typical time |
1718
|---|---|---|
1819
| `linear_search(values, target)` | Find the first matching item | O(n) |
1920
| `binary_search(values, target)` | Search ascending sorted values | O(log n) |
21+
| `two_sum(values, target)` | Find two indices whose values sum to target | O(n) average |
2022
| `frequencies(items)` | Count occurrences of hashable items | O(n) average |
2123
| `brackets_are_balanced(text)` | Check nesting of (), [], {} | O(n) |
2224

23-
Binary search requires ascending sorted input. The bracket checker ignores non-bracket characters and is not a parser for programming-language strings or comments.
25+
Binary search requires ascending sorted input. `two_sum` returns a pair of distinct indices or `None`. The bracket checker ignores non-bracket characters and is not a parser for programming-language strings or comments.
2426

25-
## Suggested extensions
27+
## Benchmark
2628

27-
- Add a benchmark comparing linear and binary search on sorted lists.
28-
- Generate randomized test cases and compare both search functions.
29-
- Add a function that returns the first matching index in binary search.
30-
- Measure memory usage as well as runtime.
29+
Compare the worst-case successful linear-search position with binary search:
30+
31+
```bash
32+
python3 benchmark_search.py --sizes 1000 10000 100000 --repeats 20
33+
```
34+
35+
Benchmark timings vary by machine and should be interpreted as observations, not guarantees. The script verifies the answers before printing timings.
36+
37+
## Test coverage
38+
39+
The unit tests include edge cases, repeated values, invalid bracket nesting, and fixed-seed randomized comparisons against a reference search. CI runs on Python 3.11 and 3.13.

0 commit comments

Comments
 (0)