Commit Graph
4178 Commits
Author SHA1 Message Date
8b11aeae4d Add Merge Sorted Arrays Algorithm with Type Hints and Doctests (#13589)
* Add merge sorted array algorithm

* updating DIRECTORY.md

* Validate input arrays for sorting in merge function

Add validation to check if input arrays are sorted.

* Correct error message assignment in merge_sorted_arrays

Fix variable assignment for error message in merge_sorted_arrays function.

* Fix sorted check for input arrays in merge function

---------

Co-authored-by: JainRamyak <JainRamyak@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-24 19:35:22 +02:00
b3f113dc4b types: constrain tim sort items to Comparable (#15432)
Co-authored-by: TayfurYldz <238304586+TayfurYldz@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-24 16:26:56 +02:00
Ramvelivelapre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clauss
18c82c9d60 Bitonic sort comparable (#15428)
* Make bitonic sort support comparable items

* Add comparable item tests for bitonic sort

* [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>
2026-09-24 16:16:10 +02:00
Fayupable d961217d5f sorts: type patience_sort's Stack for any comparable item (#15427)
Part of #15234.
2026-09-24 16:08:14 +02:00
Fayupable c41bc04f33 sorts: type unknown_sort's merge_sort for any comparable item (#15426)
Part of #15234.
2026-09-24 16:05:09 +02:00
a1fb42f058 types(iterative_merge_sort): constrain items to Comparable (#15413)
Bind merge and iter_merge_sort's element type to a Comparable Protocol so
the signatures say "a list of items that can be compared with each other"
instead of a bare list, and keep the element type in the return. result is
annotated list[T] so the generic survives the local binding.

iter_merge_sort was already in the shared SORTS battery but was missing from
test_sort_rejects_non_comparable_items, so its checklist box was only half
done; this completes it.

Also adds a doctest for the failure mode: mixing non-comparable items must
raise TypeError rather than silently mis-sort. The 'cba' doctest becomes
list('cba') so it matches the list[T] signature now on the function -- the
runtime behaviour is unchanged, since iter_merge_sort copies its input with
list() either way.

Co-authored-by: AuroraAeon <auroraeon@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-24 16:02:45 +02:00
ModusensusandChristian Clauss 16fd0d5519 sorts: make merge_insertion_sort generic over Comparable items (#15417)
Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-24 15:58:39 +02:00
FelixandChristian Clauss c4d6a2a3c3 sorts: type intro sort for comparable items (#15403)
* Refactor sorting functions to use generics

* test: cover intro sort comparable items

* Placate ruff rule PT007

* test: include intro sort in shared sort suite

* Update test_sorts.py

* Delete tests/test_intro_sort.py

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-24 15:55:56 +02:00
65b1482203 Add similarity test for square matrices (#13022)
* Add similarity test for square matrices

* Fix naming convention: MatrixLike to matrix_like

* Use TypeAlias for proper mypy type checking

* Fix CI errors: use type keyword and fix line length

* Fix docstring formatting in similar_matrices.py

Corrected formatting and punctuation in docstring.

* updating DIRECTORY.md

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-24 15:02:05 +02:00
Sarbatorepre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clausscclauss
1619583e69 feat(hashes): add Jenkins-One-At-A-Time function (#14560)
* Add joaat function for non-cryptographic hashing

Implement the Jenkins-One-At-A-Time hash function.

* Add doctest for joaat function

Added doctest examples for the joaat function and included a main block to run tests.

* Refactor joaat function variable names for prevent shadowing

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Rename function to jenkins_one_at_a_time

* 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-24 14:53:19 +02:00
Milad Khoshdelanddependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 185ef19b17 Simplify implementation (#14654)
Bumps [actions/upload-pages-artifact](https://github.com/actions/upload-pages-artifact) from 4 to 5.
- [Release notes](https://github.com/actions/upload-pages-artifact/releases)
- [Commits](https://github.com/actions/upload-pages-artifact/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/upload-pages-artifact
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-09-24 14:21:50 +02:00
ANDI FAUZAN HEDIANTOROandChristian Clauss b995597167 fix(maths): use specific exception types in collatz_sequence (#14769)
Replace generic Exception with TypeError for non-integer inputs and ValueError for non-positive integers. Split the combined validation check into two separate checks for clearer error reporting. This follows Python best practices for exception handling.

Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-24 14:20:29 +02:00
github-actions[bot]andcclauss ac86c330e0 chore: refresh Hacktoberfest 2026 prep tracker (#15430)
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-24 14:11:17 +02:00
ANDI FAUZAN HEDIANTOROandChristian Clauss 026c307820 fix(maths): correct recursive call in sum_of_digits_recursion (#14768)
sum_of_digits_recursion() was calling sum_of_digits() (the iterative version) instead of itself in the recursive case. This meant the function was not actually recursive as its name suggests.

Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-24 14:10:44 +02:00
Christian Claussandcclauss eb3776a015 Delete neural_network/gan.py_tf (#15423)
* Delete neural_network/gan.py_tf

* updating DIRECTORY.md

---------

Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-24 12:39:47 +01:00
Shashank Tyagipre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clausscclauss
bc1f8a8bb2 Adding LSTM algorithm from scratch in neural network algorithm sections (#12082)
* added lstm algorithm in neural network section.

* commented the testing lines of code

* modified code to meet contribution.md file guidelines

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add LSTM algorithm implementation in neural network section

* shorten the individual lines

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* shorten the lines

* Refactor LSTM input data initialization

* Refactor LSTM network implementation and improve code readability

* changed code a bit for meet ruff standards

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Refactor LSTM class to improve code readability and maintainability

* Refactor tqdm import in LSTM class

* Refactor tqdm import in LSTM class

* added doc tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* descriptive names + improved doctests

* Refactor LSTM class: Increase training epochs to 100

* Refactor LSTM class: Improve test method and add comments

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* added doct tests for each function

* added type hints in lstm init

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fixed type hints which were repeating in code

* written doc tests for backward pass and forward pass, fixed variable names in sigmoid function from x to input array

* fixed return type of test function to str from none

* Refactor LSTM implementation and clean up code

Removed author information and unused print statements. Updated parameter names in docstrings for consistency.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Rename stm_model to lstm_model in lstm.py

* Fix parameter name in sigmoid and tanh methods

* 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-24 11:57:28 +02:00
Thrivepre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clausscclauss
ba2d8ef44e Refactor error handling and improve logging (#13000)
* Refactor error handling and improve logging

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* httpx --> httpx2

* updating DIRECTORY.md

* Replace httpx with httpx2 for HTTP requests

* [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>
2026-09-24 09:18:56 +02:00
github-actions[bot]andcclauss feceadf5c0 chore: refresh Hacktoberfest 2026 prep tracker (#15421)
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-24 05:13:29 +02:00
Jaya PradeepandChristian Clauss 2b20de1d45 feat: add longest repeating subsequence algorithm (#14856)
Add a dynamic programming implementation of the Longest Repeating Subsequence (LRS) algorithm. This finds the longest subsequence that occurs at least twice in a string, using a variation of LCS where the string is compared with itself but characters at the same index cannot be reused. Includes comprehensive doctests and type hints.

Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-24 05:08:55 +02:00
Kaviya N SandChristian Clauss 48aeff88fd Add is_palindrome_ignore_case_and_spaces to strings/palindrome.py (#14907)
* Add is_palindrome_ignore_case_and_spaces to strings/palindrome.py

* Address review: handle punctuation, add dedicated test data for new function

* Revert unrelated benchmark timing comments per review

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-24 05:02:49 +02:00
priya-sundaram-dev f0ab75d0d2 Remove tensorflow/keras files and the keras dependency (#15420)
Per discussion in #15418, these four files are not algorithms (they are
how-to-use scripts wrapping a deep-learning framework) and dragged in the
heavy keras/tensorflow dependency stack:

- computer_vision/cnn_classification.py
- dynamic_programming/k_means_clustering_tensorflow.py
- machine_learning/lstm/lstm_prediction.py
- neural_network/input_data.py (TF MNIST data loader; nothing imports it)

Also removes the now-orphaned machine_learning/lstm/ package (only
__init__.py + sample_data.csv, which served lstm_prediction.py).

Cleanups:
- Drop keras from pyproject.toml dependencies; regenerate uv.lock
  (removes absl-py, h5py, keras, ml-dtypes, namex, optree).
- Remove the pre-release libhdf5-dev install step from build.yml and
  sphinx.yml (it existed only because keras needs hdf5).
- Drop the four stale pytest --ignore entries in build.yml.
- Remove the four DIRECTORY.md entries and the empty Lstm heading.
2026-09-24 04:45:23 +02:00
lighting9999pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clauss
c4246f0ea0 Optimize Ford-Fulkerson algorithm with type annotations and performance improvements (#13128)
* change ford_fulkerson.py

* fix ford_fulkerson.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix typo for ford_fulkerson.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Change ford_fulkerson.py

* fix I001 Error for ford_fulkerson.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix ford_fulkerson.py

* [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>
2026-09-23 23:43:40 +02:00
a3806f7d80 Add XOR-based swap algorithm for two numbers (#13018)
* Add XOR-based swap algorithm for two numbers

* updating DIRECTORY.md

* Include additional test case for xor_swap function

Add example for xor_swap with larger integers

---------

Co-authored-by: Balamurugan315 <balamuruganmsde@gmail.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-23 23:39:11 +02:00
Deepak JainI529010Deepak14JainDeepak Jainpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clauss
ff206e632c Transitive Closure Algorithm (#12940)
* Added transitive closure with tests

* updating DIRECTORY.md

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix lint issue

* lint fix

* fix line_to_long issue

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* define return type

* added type hint

* fix line_too_long lint error

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix line_too_long

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Refactor transitive closure function for clarity

Updated parameter and return type annotations for clarity. Modified variable names for consistency and corrected comments.

* Refine docstring for transitive_closure function

Updated the docstring to improve clarity and fix grammar.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: I529010 <deepak.jain04@sap.com>
Co-authored-by: Deepak14Jain <Deepak14Jain@users.noreply.github.com>
Co-authored-by: Deepak Jain <93066547+Deepak14Jain@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>
2026-09-23 22:38:22 +02:00
Priyanshu Mishrapriya-sundaram-devpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>John LawpoyeaChristian Clausscclauss
c3984d3f19 Added Random Forest Regressor as an additional prediction model. (#12767)
* Added Random Forest Regressor as an additional prediction model.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added Random Forest Regressor to main voting

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update run.py

* Update run.py

* Update run.py

Used matplotlib to plot actual vs predicted user count, forecast confidence intervals, outlier thresholds from IQR.
Added logging instead of print because in production, print() is not scalable.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update run.py

* Update run.py

* updating DIRECTORY.md

* Apply suggestion from @cclauss

* updating DIRECTORY.md

* updating DIRECTORY.md

* Apply batched suggestions from code review

Co-authored-by: priya-sundaram-dev <oc-409d01@agentmail.to>

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: John Law <johnlaw.po@gmail.com>
Co-authored-by: poyea <poyea@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
Co-authored-by: priya-sundaram-dev <oc-409d01@agentmail.to>
2026-09-23 21:45:28 +02:00
c27e95123c feat: create get_ordinary_annuity_future_value function in financial (#12358)
* feat: create get_ordinary_annuity_future_value

* Rename function to ordinary_annuity_future_value

* updating DIRECTORY.md

* updating DIRECTORY.md

---------

Co-authored-by: Jeonghyun Min <20122791@tafe.wa.edu.au>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-23 18:27:33 +02:00
793a5f79c4 feat: create (financial) get_annuity_due_future_value function (#12357)
* feat: create get_annuity_due_future_value function

* docs: modify docstring for introduction

* Rename function to annuity_due_future_value

* updating DIRECTORY.md

* updating DIRECTORY.md

---------

Co-authored-by: Jeonghyun Min <20122791@tafe.wa.edu.au>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-23 17:49:17 +02:00
IsidroChristian Clausspre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
ac6de03a92 Add Hoare partition algorithm (#12601)
* Add Hoare partition algorithm

This is another variant of in-place quicksort apart from 'Lomuto' and the 'Dutch National Flag algorithm'

* Refactor quick_sort_3_partition.py for clarity

Refactor import statement and improve docstrings for clarity.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-09-23 17:16:28 +02:00
Yashwanth Adimulamyashwanth-adimulampre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clauss
6dfe637e31 Implementing Dynamic array (#12271)
* Adding dynamic array implementation

* Adding references

* updating DIRECTORY.md

* Trying to solve pre-commit error of type overload

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Increasing test for dynamic_array.py

---------

Co-authored-by: yashwanth-adimulam <yashwanth-adimulam@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>
2026-09-23 16:23:09 +02:00
Putul Singhpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clausscclauss
42a73547fa Persistent Segment Tree (#12186)
* Suffix Array and LCP Array Implementation

* Delete divide_and_conquer/suffix_array_lcp.py

* Add files via upload

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update persistent_segment_tree.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update persistent_segment_tree.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update persistent_segment_tree.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update persistent_segment_tree.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update persistent_segment_tree.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update persistent_segment_tree.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update persistent_segment_tree.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update persistent_segment_tree.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update persistent_segment_tree.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update persistent_segment_tree.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update persistent_segment_tree.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Refactor Node class to use dataclass

Refactor Node class to use dataclass for cleaner syntax. Update PersistentSegmentTree methods to maintain functionality with the new Node structure.

* updating DIRECTORY.md

* Refactor PersistentSegmentTree implementation

* Refactor Node initialization and update methods

Refactor Node class to properly initialize value and improve type hints. Update PersistentSegmentTree methods for better clarity and maintainability.

* Apply suggestion from @cclauss

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update persistent_segment_tree.py

---------

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-23 16:16:13 +02:00
Tarun Vishwakarmapre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clausscclauss
61611418a4 Added edmonds_blossom_algorithm.py. For maximum matching in the graph. #12043 (#12056)
* Added edmonds_blossom_algorithm.py. For maximum matching in the graph.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added test for edmonds_blossom_algorithm.py in graph/tests/

Resolved the blossom data naming issue.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* resolved pre commit checks for test_edmonds_blossom_algorithm.py and edmonds_blossom_algorithm.py

* Changes in the main file and test file as test were failing due to stuck in an infinite loop.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Resolved Pre commit errors

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Resolved per commit checks and unresolved conversations

* [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>
2026-09-23 16:10:55 +02:00
wistrasypre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clausscclauss
7cf493ed70 Min Window Substring (#12133)
* Added an algorithm to the strings sub folder which finds the smallest substring of a given string which contains all of the characters in another given string.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Formatting Fixes

* Fixed a spelling issue

* Fixed incorrect function name in test cases

* Fixed incorrect function name in test cases

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added link to leetcode.

* 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-23 15:48:40 +02:00
Pritam Daspre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clausscclauss
692d38ff6f shortened the lines (#12214)
* Create README.md

* Update README.md

* Add files via upload

* Delete llm_experiments directory

* Create README.md

* Add files via upload

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add files via upload

* Delete neural_network/chatbot/main.py

* Delete neural_network/chatbot/llm_service.py

* Delete neural_network/chatbot/chatbot.py

* Delete neural_network/chatbot/db.py

* Update README.md

* Add files via upload

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add files via upload

made changes suggested by auto-checker

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add files via upload

* Add files via upload

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Delete neural_network/chatbot directory

* Add files via upload

* Add files via upload

* Add files via upload

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add files via upload

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* updating DIRECTORY.md

* Rename batch_size variable to _batch_size

---------

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-23 15:46:57 +02:00
c0fd8deab2 Add Jacobsthal numbers to maths/special_numbers (#15409)
Co-authored-by: Rakesh4440 <rakeshvarmaks999@gmail.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-23 14:53:42 +02:00
Andrey IvanovandChristian Clauss 4e817a8ef3 Add boundary checking to optimal bst (#11771)
* Add boundary checking to optimal bst

* Add additional checks to prevent IndexError

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-23 14:48:00 +02:00
d182474c4f Graph Peripherality (#11898)
* Initial Commit: Add algorithms to determine peripheral and farthest nodes in a weighted graph

- Implemented Floyd-Warshall algorithm to calculate all-pairs shortest paths,
  supporting positive edge weights for weighted graphs.
- Added functions to identify peripheral and far nodes:
  - `find_peripheral_node`: Determines the node with maximal eccentricity.
  - `find_far_node`: Finds the node with maximal farness, summing shortest-path distances.
- Included error handling for non-positive edge weights, with appropriate ValueError raising.
- Developed extensive test cases using doctests:
  - Covered single-node, fully connected, sparse, cyclic, directed acyclic, and
    disconnected graphs.
  - Validated handling of edge cases including zero and negative weights.
- Ensured code meets PEP 8 standards and passed all lint checks with `ruff`.
- Provided detailed module-level docstring with explanations of algorithms,
  complexity, and example applications.

This commit provides foundational functionality for graph-theoretical analysis
and sets up for future expansions or integrations.

* Refactor main function and update docstring formatting

* updating DIRECTORY.md

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-23 14:32:23 +02:00
49f6b461f0 Graph Centrality (#11897)
* Initial commit: Implement graph centrality algorithms for weighted graphs

- Added core functionality to compute central and median nodes in a weighted graph using:
  - Floyd-Warshall algorithm for calculating all-pairs shortest paths
  - Eccentricity for determining the central node
  - Harmonic closeness centrality for determining the median node
- Developed utility functions to handle graph data and validate positive edge weights
- Included extensive doctests to verify functionality across various graph types:
  - Single-node, disconnected, fully connected, cyclic, and directed acyclic graphs (DAGs)
- Improved code modularity and readability by refactoring functions
- Enforced code style and consistency with `ruff` and `black` formatting
- Documented the algorithmic approach, complexity, and example applications in the module docstring

* Implement style changes suggested by bot.

* updating DIRECTORY.md

* Fix formatting and improve documentation clarity

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-23 14:24:38 +02:00
Jeffrey YanceyandChristian Clauss d51160d95f Refactor Dijkstra pseudo-code and function for readability and type safety (#11875)
- Updated pseudo-code to reflect optimizations and variable naming improvements
- Added type hints to the `dijkstra` function and variables for enhanced clarity
- Introduced a `costs` dictionary to track minimum costs, avoiding redundant heap pushes
- Adjusted line lengths to comply with style guidelines

Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-23 14:17:27 +02:00
github-actions[bot]andcclauss 4ed8c99fda chore: refresh Hacktoberfest 2026 prep tracker (#15415)
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-23 14:10:17 +02:00
Nimish Srivastavapre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clausscclauss
8478904252 Added gas_station.py (#11822)
* Added gas_station.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update gas_station.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update gas_station.py

changes done

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update gas_station.py

* Update gas_station.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update gas_station.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update gas_station.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update gas_station.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* updating DIRECTORY.md

* Refactor gas station circuit solution with NamedTuple

* Clarify gas_stations argument description

Updated the argument description for gas_stations to clarify the attributes.

---------

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-23 13:43:13 +02:00
db6bf8ad59 fractional differentiation for engineering stationary features from financial time series (#11851)
* Implementation of streaming moving average

* Added reference to streaming moving average

* fixed a bug and added return type to __init__

* fractional differentiation

* cleaning up fracdiff branch

* updating DIRECTORY.md

* Apply batched suggestions from code review

Co-authored-by: priya-sundaram-dev <oc-409d01@agentmail.to>

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
Co-authored-by: priya-sundaram-dev <oc-409d01@agentmail.to>
2026-09-23 10:31:24 +02:00
github-actions[bot]andcclauss 8dba92e199 chore: refresh Hacktoberfest 2026 prep tracker (#15407)
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-23 09:45:40 +02:00
60cea20f85 feat(sorts): make odd-even transposition generic over comparable items (#15405)
Part of #15234

- Replace list[Any] with a Comparable-bounded TypeVar so
  odd_even_transposition sorts any mutually comparable items,
  not just ints
- Add str/float/int success doctests plus a TypeError rejection
  doctest for non-comparable mixed input
- Assert in-place behavior via `result is values` doctest
- Register the sort in the shared battery and in
  test_sort_rejects_non_comparable_items

Co-authored-by: ayushman-it <253447966+ayushman-it@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-23 08:46:44 +02:00
Columbus Labs cce4d26388 fix: type recursive mergesort for comparable items (#15406)
Accept any iterable of mutually comparable items and return a new list.
Part of #15234
2026-09-23 08:10:19 +02:00
2c3bcdda4e Add activity selection new algorithm (#11667)
* Add activity selection new algorithm

* updating DIRECTORY.md

* Rename x to activity

* updating DIRECTORY.md

* updating DIRECTORY.md

* Refactor activity_selection function documentation

Updated docstring and added a check for empty input.

* Fix activity_selection function test cases

---------

Co-authored-by: Hardvan <Hardvan@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
2026-09-23 08:04:45 +02:00
Reniz Shahpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clausscclauss
6a995cb4d6 add algorithm to check if given string is valid number or not (#11479)
* add algorithm to check if given string is valid number or not

Add a new file string_is_valid_number.py in string directory

* resolve comments which is create enum for states and char types extract state machine outside function

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* resolve comments which is create enum for states and char types extract state machine outside function

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* resolve ruff check failing

* change variable name from s to number_string as it is more descriptive

* rebase branch with master

* resolve comments which is create enum for states and char types extract state machine outside function

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* resolve ruff check failing

* resolve ruff check failing

* updating DIRECTORY.md

* Fix link formatting in docstring

---------

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-23 07:52:54 +02:00
CarlosZamGChristian Clausscclausspre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
836bd712a1 Add algorithm for approximating the nth root with Newton's Method (#11509)
* Add algorithm for approximating the nth root with Newton's Method

* updating DIRECTORY.md

* Fix typos in nth_root.py documentation and code

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-09-23 07:42:48 +02:00
Saurabh Mahapatrapre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clausscclauss
b021a69902 Create longest_word_in_sentence.py (#11475)
* Create longest_word_in_sentence.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update longest_word_in_sentence.py

* Update longest_word_in_sentence.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update longest_word_in_sentence.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update longest_word_in_sentence.py

* 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-23 07:42:26 +02:00
Alfian Ali Murtadlopre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Christian Clauss
c52124386e Update crawl_google_scholar_citation.py (#11655)
* Update crawl_google_scholar_citation.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Improve docstring clarity in crawl_google_scholar_citation.py

Updated the docstring for clarity and fixed formatting issues.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2026-09-23 07:23:05 +02:00
priya-sundaram-dev 2ee6d96006 build: remove Polars dependency and relock (#15404)
Polars only ships cp310-abi3 wheels, which are not loadable under the
free-threaded CPython the repo targets (.python-version = 3.14t). uv
therefore builds the ~3 MB Rust sdist from source on every uv.lock
change, making CI builds very slow. Upstream (pola-rs/polars#27955)
is not yet ready to publish free-threaded wheels.

Remove polars from pyproject.toml and relock (uv sync --upgrade && uv lock).
No source files import polars, so nothing else changes.
2026-09-22 23:49:24 +02:00