* Update pi monte carlo script to run tests with fixed seed.
* updating DIRECTORY.md
* Update pi_monte_carlo_estimation.py
* Import pi from math module
---------
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* Add XOR Linked List implementation with doctests
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add XOR Linked List implementation with doctests
* Add XOR Linked List implementation with doctests
* Add XOR Linked List implementation with doctests
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* updating DIRECTORY.md
* Refine docstring and variable comment in XOR linked list
Updated docstring for clarity and corrected 'ids' to 'IDs'.
* Refactor Node class to use dataclass
Refactor Node class to use dataclass for cleaner syntax.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* Addition to the Geometry Folder with Triangle that calculates the different triangle centers
* Addition to the Geometry Folder with Triangle that calculates the different triangle centers
* Original triangle center w/fixes for automated testing
* triangles, added more fixes for automated testing
* trying to rename triangle.py
* Fixed a documentation error
* Removed a space I suspect is preventing the automated code reviewer from completing
* Fixed a documentation error
* updating DIRECTORY.md
* Apply suggestion from @cclauss
---------
Co-authored-by: AlexB <acbucha@clemson.edu>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* Fixed
* Added TSP
* Fixes 12192
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* updating DIRECTORY.md
* Rename travelling_salesman_problem.py to graphs/travelling_salesman_problem.py
* updating DIRECTORY.md
* Fix typo in TSP validation comments
* Fix expected output for TSP function test case
Updated expected output for travelling_salesman_brute_force function.
* Fix error messages in TSP validation functions
* Modify doctest to ignore exception details
Updated doctest to ignore exception details for invalid graph input.
* Fix doctest formatting for validate_graph function
Updated doctest format for invalid graph validation.
* Update doctests in validate_graph function
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* Add naive and vectorized implementations of Linear Regression using Gradient Descent
* Add references section to docstrings in linear regression implementations
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor function signatures for improved readability in linear regression implementation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor function signatures for improved readability in linear regression implementation
* Update README sections for dataset inputs and usage instructions in linear regression implementations
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add doctests for dataset collection and gradient descent functions
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor imports and improve README formatting in linear regression scripts
* fix doctests
* Remove linear regression naive implementation script
* Refactor docstring and improve script documentation for clarity
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix formatting in gradient_descent doctest and streamline main function call
* fix doctest
* updating DIRECTORY.md
* Change httpx to httpx2 and update docstring
Updated import from httpx to httpx2 and modified docstring for dataset return type.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* Add Adagrad optimizer implementation
- Implements Adagrad (Adaptive Gradient) using pure NumPy
- Adapts learning rate individually for each parameter
- Includes comprehensive docstrings and type hints
- Adds doctests for validation
- Provides usage example demonstrating convergence
- Follows PEP8 coding standards
- Part of issue #13662
* Add Adam and Nesterov Accelerated Gradient optimizers
- Implements Adam (Adaptive Moment Estimation) optimizer
- Implements Nesterov Accelerated Gradient (NAG) optimizer
- Both use pure NumPy without deep learning frameworks
- Includes comprehensive docstrings and type hints
- Adds doctests for validation
- Provides usage examples demonstrating convergence
- Follows PEP8 coding standards
- Part of issue #13662
* updating DIRECTORY.md
---------
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* docs: enhance README with table of contents, installation guide, and features section
- Add comprehensive table of contents for easy navigation
- Include detailed installation steps with virtual environment setup
- Add usage examples showing how to run and import algorithms
- Create features section listing all algorithm categories
- Add explicit license section with MIT License information
- Expand contributing section with quick start guide
- Add about section explaining repository purpose
Fixes#13111
* docs: enhance README with table of contents, installation guide, and features section
- Add comprehensive table of contents for easy navigation
- Include detailed installation steps with virtual environment setup
- Add usage examples showing how to run and import algorithms
- Create features section listing all algorithm categories
- Add explicit license section with MIT License information
- Expand contributing section with quick start guide
- Add about section explaining repository purpose
Fixes#13111
* feat: add Vision Transformer (ViT) implementation for image classification
- Implement complete ViT architecture with patch embedding
- Add positional encoding with learnable CLS token
- Include scaled dot-product attention mechanism
- Implement transformer encoder blocks with layer normalization
- Add feed-forward network with GELU activation
- Include comprehensive docstrings and type hints
- Add doctests for all functions
- Provide example usage demonstrating the complete pipeline
Fixes#13326
* fix: resolve ruff linting errors in vision_transformer.py
- Replace Optional with X | None syntax (UP045)
- Use np.random.Generator instead of legacy np.random methods (NPY002)
- Fix line length violations (E501)
- Assign f-string literals to variables in exceptions (EM102)
- Remove unused variables and parameters (RUF059, F841)
- Add noqa comment for intentionally unused API parameter
- All doctests still pass successfully
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor: use descriptive parameter names instead of 'x'
- Rename 'x' to 'embeddings' in layer_norm, feedforward_network,
and transformer_encoder_block functions
- Update all docstring examples to use 'embeddings'
- Improves code readability per algorithms-keeper bot feedback
- Fix noqa comment placement for unused num_heads parameter
- All doctests and ruff checks pass
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* updating DIRECTORY.md
* Remove redundant sections from README.md
Removed sections on Table of Contents, About, Features, and Contributing from README.
---------
Co-authored-by: devvratpathak <devvrat.23bce8848@vitapstudent.ac.in>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <pre-commit-ci[bot]@users.noreply.github.com>
* Add derivative(t) method to BezierCurve class
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* updating DIRECTORY.md
* Apply suggestion from @cclauss
---------
Co-authored-by: Suvidha <nsuvidhasree05@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* updating DIRECTORY.md
* sorts: support comparable items in merge sort
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* sorts: use type parameters in merge sort
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix grammar in merge sort docstring
Corrected minor grammatical errors in docstring.
* Update DIRECTORY.md with new algorithms and functions
* updating DIRECTORY.md
* updating DIRECTORY.md
---------
Co-authored-by: kadubhumika <kadubhumika@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* Algorithm to get maximum path sum of a binary tree.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Added "TreeNode | None" as traverse method argument type hints to accept both
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Added doctest for construct_tree and type hints for TreeNode
* Added type hint and doctest
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Preformatted using black
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Organized imports
* updating DIRECTORY.md
* Apply suggestion from @cclauss
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* Create logarithmic_series.py
This is an implementation of logarithmic series in Python.
Reference: https://math.stackexchange.com/questions/3973429/what-is-a-logarithmic-series
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update logarithmic_series.py
Fixed long line issue
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update logarithmic_series.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* updating DIRECTORY.md
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* Added Trailing Zero Algo
Created an algorithm that return the trailing zeroes of a number
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* updating DIRECTORY.md
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* Add files via upload
An algorithm to find intersection between 2 lines.
* Added doctest to function
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fixed ruff issues
* updating DIRECTORY.md
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* weddle's integration rule
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* checks passed
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* added return type hint
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Added type hints to function parameters and return types
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* added descriptive names
* safe eval used
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* changed parameter hint
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* updated function signatures, type hints, and docstrings; modified function implementations and variable names.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* changes made in doctest
* updating DIRECTORY.md
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* Added function that calculates Pell numbers
* Fixed ruff error
* Renamed input argument to be more descriptive
* updating DIRECTORY.md
---------
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
Drop machine_learning/xgboost_classifier.py and
machine_learning/xgboost_regressor.py. Both were thin "how-to-use"
wrappers around sklearn's XGBClassifier/XGBRegressor rather than
from-scratch implementations, and the classifier's only doctest was
already disabled (# THIS TEST IS BROKEN!!), so it was never exercised
in CI.
xgboost is one of the heaviest compiled dependencies in the tree (large
wheel, needs OpenMP/libgomp at runtime, no free-threaded wheel yet), and
gradient boosting is already implemented from scratch in
machine_learning/gradient_boosting_classifier.py and
gradient_boosting_regressor.py, so no algorithm coverage is lost.
Removes the xgboost dependency from pyproject.toml, its (and its
xgboost-only transitive dep nvidia-nccl-cu13) entries from uv.lock, and
the two DIRECTORY.md links.
Refs #15081
* Skill: New pull request for TheAlgorithms/Python
@priya-sundaram-dev, please review and suggest any changes. We want to make sure that the keeper does not close new PRs as invalid.
* updating DIRECTORY.md
* Update pull request instructions in SKILL.md
Clarified instructions for creating a new pull request and emphasized the importance of branch naming.
* Clarify Markdown checkbox requirement for PRs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* Skill: fix uv.lock wording; add DIRECTORY.md/README.md auto-gen note (#15216)
- Clarify that uv.lock is regenerated by the uv-lock pre-commit hook when a
legitimate dependency is added; only hand-edits/reverts break the keeper.
- Add a checklist item: DIRECTORY.md and README.md are bot-generated, don't
hand-edit them.
---------
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: priya-sundaram-dev <oc-409d01@agentmail.to>
* Add a table of contents to DIRECTORY.md
Generate a linked table of contents of the top-level sections at the top
of DIRECTORY.md so readers can jump straight to a category, as suggested
in #13239 / #13111. The list is built in scripts/build_directory_md.py
(with a new md_anchor helper + doctests) so DIRECTORY.md stays fully
auto-generated.
* Address review: numbered ToC + link section headings to their directories
- Table of Contents is now a numbered list, so the final number shows the
total count of algorithm folders at a glance.
- Each top-level section heading links to its algorithm directory (e.g.
## [Sorts](sorts)), so clicking a section title jumps straight to the folder.
* feat: add Kelly Criterion and Sharpe Ratio to financial algorithms
* fix: replace ambiguous unicode sigma and shorten long docstring line
* fix: resolve pre-existing ruff errors in hashing, jump_search, and lda
* Apply batched suggestions from code review
Co-authored-by: Christian Clauss <cclauss@me.com>
* updating DIRECTORY.md
---------
Co-authored-by: Samrat Chowdhury <sam@rvmediacorp.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* Add missing type hints to hill_climbing.py
This commit adds the missing type annotations to searches/hill_climbing.py.
- Added type annotation for function_to_optimize using Callable [[int, int], int]
- Added return type hints to get_neighbors, __hash__, __eq__, and __str__
- Added missing type hint for search_prob in hill_climbing()
- Improved type clarity while preserving existing logic
- Used modern Python type hints (PEP 585)
This improves readability and typing consistency across the repository.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix unnecessary empty iterable in deque initialization (RUF037)
* Update type hint for objective function to allow float return values
* Update score() return type to support int | float
Mypy reported an incompatible return type because function_to_optimize may return float values.
Updated score() return type from int to int | float for full compatibility.
* Initialize deque with empty list for None values
* updating DIRECTORY.md
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-05 23:50:24 +02:00
Michael HauseggerTheRealHauiChristian Clausspre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>pre-commit-ci[bot] <pre-commit-ci[bot]@users.noreply.github.com>
* Added some Unit Tests to increase test code coverage
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* updating DIRECTORY.md
---------
Co-authored-by: TheRealHaui <michael.hausegger@hausegger.tech>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <pre-commit-ci[bot]@users.noreply.github.com>
* CPU Scheduling Algorithms with user input
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* updating DIRECTORY.md
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>