* fix: restrict introsort heap fallback to the active range
* test: cover introsort heap fallback range boundaries
* fix: sort introsort heap fallback ranges without copying
* test: cover introsort heap sort range boundaries and default end
* ci: try Python 3.15 release candidate (DRAFT)
Point the repo's .python-version at 3.15 so every workflow that reads
python-version-file runs on the 3.15 release candidate (allow-prereleases
is already enabled across all workflows). Add the 3.15 trove classifier
and bump scipy>=1.18.1, which is the first scipy with cp315 manylinux
wheels, so uv installs it as a wheel rather than building from source.
Rebuilt on current master: the earlier version of this PR edited the
per-workflow `python-version: 3.14` lines, but master has since moved
the interpreter to a single `.python-version` file, so the change is now
a one-line switch there.
Purpose is to document which dependencies/tests are not yet 3.15-ready.
Must stay DRAFT until Python 3.15 GA (early October). Requested in #15081.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Upgrade to Python 3.15t
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
* fix(sorts): make smoothsort generic over Comparable items
* The TypeVar is no longer needed.
---------
Co-authored-by: Christian Clauss <cclauss@me.com>
* Document addition function using bitwise operations
Added docstring explaining the bitwise addition method.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor addition function documentation and output
Updated docstring to clarify the use of bitwise operations for addition. Modified the output format of the result to include both input values.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
* Improve documentation and educational comments in find_max.py
- Added clear explanation of Divide and Conquer approach
- Improved parameter descriptions for better understanding
- Enhanced comments to explain the algorithm steps
- Better documentation for educational purposes
* [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>
* added merge interval problem on the array ds
* removed typing which is deprecated
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor type hints in merge_intervals function
Updated type hints from List to built-in list for compatibility.
* Enhance merge_intervals function documentation
Added edge cases handling and updated complexity notes.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor docstring and type hints in merge_intervals
Updated type hints and docstring formatting in merge_intervals function.
* Refactor merge_intervals function docstring
Updated docstring formatting and improved error message clarity.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update data_structures/arrays/merge_intervals.py
Co-authored-by: priya-sundaram-dev <oc-409d01@agentmail.to>
* 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: priya-sundaram-dev <oc-409d01@agentmail.to>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* types(reverse_selection): constrain items to Comparable
Bind reverse_selection_sort's element type to a Comparable Protocol so the
signature says "a list of items that can be compared with each other"
instead of a bare list, and keep the element type in the return.
reverse_subarray only swaps elements and never compares them, so its
TypeVar stays unbounded.
Also adds doctests for a comparable non-int type (strings, floats) and for
the failure mode: mixing non-comparable items must raise TypeError rather
than silently mis-sort. The test battery picks the sort up for the shared
cases and for the rejection check.
* updating DIRECTORY.md
---------
Co-authored-by: AuroraAeon <auroraeon@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* feat(arrays): Add in-place array reversal algorithm
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Enhance docstring for reverse_array function
Updated docstring to clarify that the function returns the reversed list.
* Clarify return value in reverse_array function
Updated docstring to clarify that the function returns the reversed list. Modified example usage to display the reversed array correctly.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
* 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>
* 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>
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>
* 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>
* 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>
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>
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>
* 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>
* 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>
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>
* 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>
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.
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>