Commit Graph

430 Commits

Author SHA1 Message Date
Sai Harsha Kottapalli
12e8e9ca87
Add DocTests to is_palindrome.py (#10081)
* add doctest ut

* test complete

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

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

* format

* ruff update

* cover line 154

* Update data_structures/linked_list/is_palindrome.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* use dataclass

* pre-commit fix

* Fix mypy errors

* use future annotations

---------

Co-authored-by: Harsha Kottapalli <skottapalli@microsoft.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>
2023-10-09 14:06:16 +02:00
halfhearted
2d02500332
equilibrium index in an array (#9856)
* equilibrium index in an array

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

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

* equilibrium index in an array

* equilibrium index in an array

* equilibrium index in an array removed type in docstring

---------

Co-authored-by: ArunSiva <Arunsiva003@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-10-09 08:44:49 +13:00
Christian Clauss
d0c54acd75
Use dataclasses in singly_linked_list.py (#9886) 2023-10-06 15:31:11 +13:00
JeevaRamanathan
17af644449
Symmetric tree (#9871)
* symmectric tree

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

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

* removed trailing spaces

* escape sequence fix

* added return type

* added class

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

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

* wordings fix

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

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

* added static method

* added type

* added static method

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

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

* wordings fix

* testcase added

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

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

* testcase added for mirror function

* testcase added for mirror function

* made the requested changes

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

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

* made the requested changes

* doc test added for symmetric, asymmetric

* Update symmetric_tree.py

---------

Co-authored-by: jeevaramanthan.m <jeevaramanathan.m@infosys.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>
2023-10-06 02:00:58 +02:00
Christian Clauss
5869fda742
print reverse: A LinkedList with a tail pointer (#9875)
* print reverse: A LinkedList with a tail pointer

* updating DIRECTORY.md

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2023-10-06 10:55:13 +13:00
Wei Jiang
55ee273419
[bug fixing] Edge case of the double ended queue (#9823)
* fix the edge case of the double ended queue pop the last element

* refactoring doc

---------

Co-authored-by: Jiang15 <weijiang@weijiangs-MacBook-Pro.local>
2023-10-05 10:00:48 -04:00
Bama Charan Chhandogi
d5806258d4
add median of two sorted array (#9386)
* add median of two sorted array

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

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

* fix syntax

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

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

* fix syntax

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

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

* improve code

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

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

* add documentation

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

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

* update

* [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>
2023-10-04 20:18:59 +02:00
halfhearted
d74349793b
Arunsiva003 patch 1 flatten tree (#9695)
* infix to prefix missing feature added

* infix to prefix missing feature added

* infix to prefix missing feature added

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

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

* infix to prefix missing feature added (comments)

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

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

* infix to prefix missing feature added (comments)

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

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

* newly updated infix_to_prefix

* newly updated infix_to_prefix_2

* newly updated infix_to_prefix_3

* from the beginning

* Created flatten_binarytree_to_linkedlist.py

* Update flatten_binarytree_to_linkedlist.py

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

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

* Update flatten_binarytree_to_linkedlist.py

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

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

* Update flatten_binarytree_to_linkedlist.py

* Update flatten_binarytree_to_linkedlist.py

* Update flatten_binarytree_to_linkedlist.py

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

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

* Update flatten_binarytree_to_linkedlist.py (space added)

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

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

* Update flatten_binarytree_to_linkedlist.py space added

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

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

* Update flatten_binarytree_to_linkedlist.py

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

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

* flatten binary tree to linked list - 1

* flatten binary tree to linked list final

* flatten binary tree to linked list final

* review updated

* Update flatten_binarytree_to_linkedlist.py

* Update .pre-commit-config.yaml

* Update flatten_binarytree_to_linkedlist.py

* Update flatten_binarytree_to_linkedlist.py

---------

Co-authored-by: ArunSiva <Arunsiva003@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>
2023-10-04 18:39:28 +02:00
Tianyi Zheng
dfdd78135d
Fix mypy errors in circular_linked_list.py and swap_nodes.py (#9707)
* updating DIRECTORY.md

* Fix mypy errors in circular_linked_list.py

* Fix mypy errors in swap_nodes.py

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2023-10-04 18:05:00 +02:00
Siddhant Totade
3fd3497f15
Add Comments (#9668)
* docs : add comment in circular_linked_list.py and swap_nodes.py

* docs : improve comments

* docs : improved docs and tested on pre-commit

* docs : add comment in circular_linked_list.py and swap_nodes.py

* docs : improve comments

* docs : improved docs and tested on pre-commit

* docs : modified comments

* Update circular_linked_list.py

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

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

* docs : improved

* Update data_structures/linked_list/circular_linked_list.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update data_structures/linked_list/circular_linked_list.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update data_structures/linked_list/swap_nodes.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update data_structures/linked_list/swap_nodes.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update data_structures/linked_list/swap_nodes.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update data_structures/linked_list/swap_nodes.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update requirements.txt

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update data_structures/linked_list/circular_linked_list.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Apply suggestions from code review

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

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

* Update circular_linked_list.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>
2023-10-04 11:25:26 +02:00
Bama Charan Chhandogi
e798e5acde
add reverse k group linkedlist (#9323)
* add reverse k group linkedlist

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

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

* update

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

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

* update

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

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

* update

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

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

* update

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

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

* update

* Update reverse_k_group.py

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

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

* Update reverse_k_group.py

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

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

* Update reverse_k_group.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>
2023-10-02 02:19:39 +02:00
aryan1165
18cdbc4165
binary_search_traversals.py made memory-friendly using generators. Fixes #8725 completely. (#9237)
* Made binary tree memory-friendly using generators based travels. Fixes
#8725

* Made binary tree memory-friendly using generators based travels. Fixes
#8725

* Fixed pre-commit errors
2023-10-01 12:54:05 -04:00
Muhammad Umer Farooq
bacad12a1f
[NEW ALGORITHM] Rotate linked list by K. (#9278)
* Rotate linked list by k.

* Rotate linked list by k.

* updated variable name.

* Update data_structures/linked_list/rotate_linked_list_by_k.py

Co-authored-by: Christian Clauss <cclauss@me.com>

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

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

* Update data_structures/linked_list/rotate_linked_list_by_k.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update data_structures/linked_list/rotate_linked_list_by_k.py

* Make Node a dataclass

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-10-01 18:11:16 +02:00
aryan1165
eaa87bd791
Made binary tree memory-friendly using generators based travels. Fixes (#9208)
#8725
2023-10-01 04:43:48 -04:00
aryan1165
320d895b86
Fixed permute_recursive() by passing nums.copy(). Fixes #9014 (#9161)
* Fixes #9014

* Fixed permute_recursive() by passing nums.copy()
2023-10-01 00:06:15 -04:00
Saksham Saha
c9b4b8002f
Added an add at position subroutiune to linked list (#9020)
* added addAtPosition to simple linked list

* added addAtPosition to simple linked list

* modified the add function to take an optional position command

* fixed type safety errors:

* fixed type safety errors:

* fixed type safety errors:

* fixed type safety errors:

* fixed size error

* fixed size error

* added doctest and updates the else after checking if posiiton argument less than 0 or not

* added doctest and updates the else after checking if posiiton argument less than 0 or not

* fixed the contributing.md mistake

* added doctest for out of bounds position value, both negative and positive
2023-09-08 08:20:28 -04:00
pre-commit-ci[bot]
421ace81ed
[pre-commit.ci] pre-commit autoupdate (#9013)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.285 → v0.0.286](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.285...v0.0.286)
- [github.com/tox-dev/pyproject-fmt: 0.13.1 → 1.1.0](https://github.com/tox-dev/pyproject-fmt/compare/0.13.1...1.1.0)

* updating DIRECTORY.md

* Fis ruff rules PIE808,PLR1714

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2023-08-29 15:18:10 +02:00
Arijit De
0a9438071e
Updated postfix_evaluation.py to support Unary operators (#8787)
* Updated postfix_evaluation.py to support Unary operators and floating point numbers Fixes #8754 and #8724

Also merged evaluate_postfix_notations.py and postfix_evaluation.py into postfix_evaluation.py

Signed-off-by: Arijit De <arijitde2050@gmail.com>

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

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

* Updated postfix_evaluation.py to support Unary operators and floating point numbers. Fixes #8754 and formatted code to pass ruff and black test.

Also merged evaluate_postfix_notations.py and postfix_evaluation.py into postfix_evaluation.py which fixes #8724 and made sure it passes doctest

Signed-off-by: Arijit De <arijitde2050@gmail.com>

* Fixed return type hinting required by pre commit for evaluate function

Signed-off-by: Arijit De <arijitde2050@gmail.com>

* Changed line 186 to return only top of stack instead of calling the get_number function as it was converting float values to int, resulting in data loss. Fixes #8754 and #8724

Signed-off-by: Arijit De <arijitde2050@gmail.com>

* Made the requested changes

Also changed the code to make the evaluate function first convert all the numbers and then process the valid expression.

* Fixes #8754, #8724 Updated postfix_evaluation.py

postfix_evaluation.py now supports Unary operators and floating point numbers.
Also merged evaluate_postfix_notations.py and postfix_evaluation.py into postfix_evaluation.py which fixes #8724. Added a doctest example with unary operator.

* Fixes #8754, #8724 Updated postfix_evaluation.py

postfix_evaluation.py now supports Unary operators and floating point numbers.
Also merged evaluate_postfix_notations.py and postfix_evaluation.py into postfix_evaluation.py which fixes #8724. Added a doctest example with unary operator.

* Fixes #8754, #8724 Updated the parse_token function of postfix_evaluation.py

ostfix_evaluation.py now supports Unary operators and floating point numbers.
Also merged evaluate_postfix_notations.py and postfix_evaluation.py into postfix_evaluation.py which fixes #8724. Added a doctest example with unary operator and invalid expression.

* Fixes #8754, #8724 Updated postfix_evaluation.py

postfix_evaluation.py now supports Unary operators and floating point numbers.
Also merged evaluate_postfix_notations.py and postfix_evaluation.py into postfix_evaluation.py which fixes #8724. Added a doctest example with unary operator and invalid expression.

* Update postfix_evaluation.py

* Update postfix_evaluation.py

* Update postfix_evaluation.py

* Update postfix_evaluation.py

* Update postfix_evaluation.py

---------

Signed-off-by: Arijit De <arijitde2050@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>
2023-08-23 14:36:59 +02:00
Caeden Perelli-Harris
fceacf977f
Fix type errors in permutations (#9007)
* updating DIRECTORY.md

* types(permuations): Rename permute2

* Apply suggestions from code review

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>

* fix(permutations): Call permute_recursive

* fix(permutations): Correct permutations order

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
2023-08-22 02:33:47 -07:00
isidroas
efaf526737
BST and RSA doctest (#8693)
* rsa key doctest

* move doctest to module docstring

* all tests to doctest

* moved is_right to property

* is right test

* fixed rsa doctest import

* Test error when deleting non-existing element

* fixing ruff EM102

* convert property 'is_right' to one-liner

Also use 'is' instead of '=='

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>

* child instead of children

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>

* remove type hint

* Update data_structures/binary_tree/binary_search_tree.py

---------

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
2023-08-15 16:04:53 -07:00
Tianyi Zheng
ae0fc85401
Fix ruff errors (#8936)
* Fix ruff errors

Renamed neural_network/input_data.py to neural_network/input_data.py_tf
because it should be left out of the directory for the following
reasons:

1. Its sole purpose is to be used by neural_network/gan.py_tf, which is
   itself left out of the directory because of issues with TensorFlow.

2. It was taken directly from TensorFlow's codebase and is actually
   already deprecated. If/when neural_network/gan.py_tf is eventually
   re-added back to the directory, its implementation should be changed
   to not use neural_network/input_data.py anyway.

* updating DIRECTORY.md

* Change input_data.py_tf file extension

Change input_data.py_tf file extension because algorithms-keeper bot is being picky about it

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2023-08-09 13:25:30 +05:30
AmirSoroush
ce218c57f1
fixes #8673; Add operator's associativity check for stacks/infix_to_p… (#8674)
* fixes #8673; Add operator's associativity check for stacks/infix_to_postfix_conversion.py

* fix ruff N806 in stacks/infix_to_postfix_conversion.py

* Update data_structures/stacks/infix_to_postfix_conversion.py

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>

* Update data_structures/stacks/infix_to_postfix_conversion.py

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>

---------

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
2023-08-01 11:23:34 -07:00
roger-sato
0b0214c42f
Handle empty input case in Segment Tree build process (#8718) 2023-07-31 11:46:30 -07:00
AmirSoroush
384c407a26
Enhance the implementation of Queue using list (#8608)
* enhance the implementation of queue using list

* enhance readability of queue_on_list.py

* rename 'queue_on_list' to 'queue_by_list' to match the class name
2023-07-30 19:07:35 -07:00
AmirSoroush
d4f2873e39
add reverse_inorder traversal to binary_tree_traversals.py (#8726)
* add reverse_inorder traversal to binary_tree_traversals.py

* Apply suggestions from code review

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>

---------

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
2023-07-30 17:54:15 -07:00
Sangmin Jeon
a03b739d23
Fix radix_tree.py insertion fail in ["*X", "*XX"] cases (#8870)
* Fix insertion fail in ["*X", "*XX"] cases

Consider a word, and a copy of that word, but with the last letter repeating twice. (e.g., ["ABC", "ABCC"])
When adding the second word's last letter, it only compares the previous word's prefix—the last letter of the word already in the Radix Tree: 'C'—and the letter to be added—the last letter of the word we're currently adding: 'C'. So it wrongly passes the "Case 1" check, marks the current node as a leaf node when it already was, then returns when there's still one more letter to add.
The issue arises because `prefix` includes the letter of the node itself. (e.g., `nodes: {'C' : RadixNode()}, is_leaf: True, prefix: 'C'`) It can be easily fixed by simply adding the `is_leaf` check, asking if there are more letters to be added.

- Test Case: `"A AA AAA AAAA"`
  - Fixed correct output:
  ```
  Words: ['A', 'AA', 'AAA', 'AAAA']
  Tree:
  - A   (leaf)
  -- A   (leaf)
  --- A   (leaf)
  ---- A   (leaf)
  ```
  - Current incorrect output:
  ```
  Words: ['A', 'AA', 'AAA', 'AAAA']
  Tree:
  - A   (leaf)
  -- AA   (leaf)
  --- A   (leaf)
  ```

*N.B.* This passed test cases for [Croatian Open Competition in Informatics 2012/2013 Contest #3 Task 5 HERKABE](https://hsin.hr/coci/archive/2012_2013/)

* Add a doctest for previous fix

* improve doctest readability
2023-07-24 11:29:05 +02:00
Caeden Perelli-Harris
93fb169627
[Upgrade Ruff] Fix all errors raised from ruff (#8879)
* chore: Fix tests

* chore: Fix failing ruff

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

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

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

* chore: Fix ruff errors

* chore: Fix ruff errors

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

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

* Update cellular_automata/game_of_life.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* chore: Update ruff version in pre-commit

* chore: Fix ruff errors

* Update edmonds_karp_multiple_source_and_sink.py

* Update factorial.py

* Update primelib.py

* Update min_cost_string_conversion.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>
2023-07-22 12:05:10 +02:00
pre-commit-ci[bot]
c9ee6ed188
[pre-commit.ci] pre-commit autoupdate (#8853)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.275 → v0.0.276](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.275...v0.0.276)

* Update double_ended_queue.py

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

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

* Update double_ended_queue.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>
2023-07-04 00:20:35 +02:00
Himanshu Tomar
331585f3f8
Algorithm: Calculating Product Sum from a Special Array with Nested Structures (#8761)
* Added minimum waiting time problem solution using greedy algorithm

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

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

* ruff --fix

* Add type hints

* Added two more doc test

* Removed unnecessary comments

* updated type hints

* Updated the code as per the code review

* Added recursive algo to calculate product sum from an array

* Added recursive algo to calculate product sum from an array

* Update doc string

* Added doctest for product_sum function

* Updated the code and added more doctests

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

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

* Added more test coverage for product_sum method

* Update product_sum.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>
2023-06-23 10:26:05 +02:00
Linus M. Henkel
5b0890bd83
Dijkstra algorithm with binary grid (#8802)
* Create TestShiva

* Delete TestShiva

* Implementation of the Dijkstra-Algorithm in a binary grid

* Update double_ended_queue.py

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

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

* Update least_common_multiple.py

* Update sol1.py

* Update pyproject.toml

* Update pyproject.toml

* https://github.com/astral-sh/ruff-pre-commit v0.0.274

---------

Co-authored-by: ShivaDahal99 <130563462+ShivaDahal99@users.noreply.github.com>
Co-authored-by: jlhuhn <134317018+jlhuhn@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-06-22 13:49:09 +02:00
Frank-1998
b0f871032e
Fix removing the root node in binary_search_tree.py removes the whole tree (#8752)
* fix issue #8715

* [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>
2023-06-18 18:30:06 +02:00
Sundaram Kumar Jha
4a27b54430
Update permutations.py (#8102) 2023-05-31 12:56:59 +12:00
Christian Clauss
4b79d771cd
Add more ruff rules (#8767)
* Add more ruff rules

* Add more ruff rules

* pre-commit: Update ruff v0.0.269 -> v0.0.270

* Apply suggestions from code review

* Fix doctest

* Fix doctest (ignore whitespace)

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

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

---------

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-05-26 09:34:17 +02:00
Christian Clauss
4c1f876567
Solving the Top k most frequent words problem using a max-heap (#8685)
* Solving the `Top k most frequent words` problem using a max-heap

* Mentioning Python standard library solution in `Top k most frequent words` docstring

* ruff --fix .

* updating DIRECTORY.md

---------

Co-authored-by: Amos Paribocci <aparibocci@gmail.com>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2023-04-27 23:02:07 +05:30
isidroas
14bdd174bb
Bloom Filter (#8615)
* Bloom filter with tests

* has functions constant

* fix type

* isort

* passing ruff

* type hints

* type hints

* from fail to erro

* captital leter

* type hints requested by boot

* descriptive name for m

* more descriptibe arguments II

* moved movies_test to doctest

* commented doctest

* removed test_probability

* estimated error

* added types

* again hash_

* Update data_structures/hashing/bloom_filter.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* from b to bloom

* Update data_structures/hashing/bloom_filter.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update data_structures/hashing/bloom_filter.py

Co-authored-by: Christian Clauss <cclauss@me.com>

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

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

* syntax error in dict comprehension

* from goodfather to godfather

* removed Interestellar

* forgot the last Godfather

* Revert "removed Interestellar"

This reverts commit 35fa5f5c4b.

* pretty dict

* Apply suggestions from code review

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

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

* Update bloom_filter.py

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-04-08 19:39:24 +02:00
Christian Clauss
2f9b03393c
Delete queue_on_two_stacks.py which duplicates queue_by_two_stacks.py (#8624)
* Delete queue_on_two_stacks.py which duplicates queue_by_two_stacks.py

* updating DIRECTORY.md

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2023-04-08 17:46:19 +05:30
amirsoroush
5cb0a000c4
Queue implementation using two Stacks (#8617)
* Queue implementation using two Stacks

* fix typo in queue/queue_on_two_stacks.py

* add 'iterable' to queue_on_two_stacks initializer

* make queue_on_two_stacks.py generic class

* fix ruff-UP007 in queue_on_two_stacks.py

* enhance readability in queue_on_two_stacks.py

* Create queue_by_two_stacks.py

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
2023-04-08 13:41:08 +02:00
amirsoroush
63710883c8
Remove extra len calls in doubly-linked-list's methods (#8600) 2023-04-01 17:53:21 +05:30
amirsoroush
e4d90e2d5b
change space complexity of linked list's __len__ from O(n) to O(1) (#8183) 2023-04-01 08:26:43 +02:00
pre-commit-ci[bot]
3f9150c1b2
[pre-commit.ci] pre-commit autoupdate (#8294)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/charliermarsh/ruff-pre-commit: v0.0.255 → v0.0.257](https://github.com/charliermarsh/ruff-pre-commit/compare/v0.0.255...v0.0.257)

* Fix PLR1711 Useless  statement at end of 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>
2023-03-20 22:16:13 +01:00
Christian Clauss
521fbca61c
Replace flake8 with ruff (#8184) 2023-03-16 13:31:29 +01:00
Christian Clauss
c96241b5a5
Replace bandit, flake8, isort, and pyupgrade with ruff (#8178)
* Replace bandit, flake8, isort, and pyupgrade with ruff

* Comment on ruff rules

* updating DIRECTORY.md

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2023-03-15 13:58:25 +01:00
Andrey
b797e437ae
Add hashmap implementation (#7967) 2023-03-14 01:31:27 +01:00
Christian Clauss
64543faa98
Make some ruff fixes (#8154)
* Make some ruff fixes

* Undo manual fix

* Undo manual fix

* Updates from ruff=0.0.251
2023-03-01 17:23:33 +01:00
Christian Clauss
c909da9b08
pre-commit: Upgrade psf/black for stable style 2023 (#8110)
* pre-commit: Upgrade psf/black for stable style 2023

Updating https://github.com/psf/black ... updating 22.12.0 -> 23.1.0 for their `2023 stable style`.
* https://github.com/psf/black/blob/main/CHANGES.md#2310

> This is the first [psf/black] release of 2023, and following our stability policy, it comes with a number of improvements to our stable style…

Also, add https://github.com/tox-dev/pyproject-fmt and https://github.com/abravalheri/validate-pyproject to pre-commit.

I only modified `.pre-commit-config.yaml` and all other files were modified by pre-commit.ci and psf/black.

* [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>
2023-02-01 18:44:54 +05:30
Christian Clauss
08c2245705
Upgrade to flake8 v6 (#8007)
* Upgrade to flake8 v6

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2022-11-29 16:56:41 +01:00
Mark Mayo
f32d611689
clean of unnecessary checks, imports, calls (#7993) 2022-11-21 00:00:27 +13:00
Dhruv Manilawala
8bfd1c844b
fix: mypy 0.991 issues (#7988)
* fix: mypy 0.991 issues

* fix: invalid condition for base case
2022-11-15 18:29:14 +01:00
Dhruv Manilawala
3bf86b91e7
fix: no implicit optional (#7984) 2022-11-15 14:55:14 +01:00
Alexander Pantyukhin
7b2eca0243
add distribute coins (#7975)
* add distribute coins

* updating DIRECTORY.md

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

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

* fix review notes

* fix typehint

* fix type in TreeNode

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-11-10 15:49:38 +13:00
Caeden Perelli-Harris
daa1c7529a
Raise error not string (#7945)
* ci: Add `B023` to `.flake8` ignores

* refactor: Return `bool`/raise Exception

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

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

* revert: Remove previous branch commit

* Update data_structures/binary_tree/segment_tree_other.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* feat: Apply `__repr__` changes

* chore: Fix failing tests

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

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

* Update data_structures/binary_tree/segment_tree_other.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* test: Fix doctests

* random.choice(population_score[:N_SELECTED])[0]

* Update basic_string.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>
2022-11-06 15:54:44 +01:00
Alexander Pantyukhin
7f1a5521f4
add prefix sum (#7959)
* add prefix sum

* updating DIRECTORY.md

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

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

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-11-04 20:30:32 +13:00
Alexander Pantyukhin
3e1cb70abf
add algorithm to check binary search tree (#7947)
* add algorithm to check binary search tree

* add tests

* add leetcode link

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

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

* fix typehints

* typehints fixes

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

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

* Update data_structures/binary_tree/is_bst.py

Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>

* Update data_structures/binary_tree/is_bst.py

Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>

* Update data_structures/binary_tree/is_bst.py

Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>

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

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

* fix flake8

* fix typehint

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

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

* add TreeNode resolving

* Update data_structures/binary_tree/is_bst.py

Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>

* Update data_structures/binary_tree/is_bst.py

Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>

* Update data_structures/binary_tree/is_bst.py

Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>

* Update data_structures/binary_tree/is_bst.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* change func name

* Update data_structures/binary_tree/is_bst.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* review notes fixes.

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

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

* fix flake8

* fix flake 8

* fix doctest

* Update data_structures/binary_tree/is_bst.py

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2022-11-03 21:03:37 +01:00
Christian Clauss
45b3383c39
Flake8: Drop ignore of issue A003 (#7949)
* Flake8: Drop ignore of issue A003

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2022-11-02 19:20:45 +01:00
Alex de la Cruz
b2165a65fc
Added Radix Tree in data structures (#6616)
* added radix tree to data structures

* added doctests

* solved flake8

* added type hints

* added description for delete function

* Update data_structures/trie/radix_tree.py

* Update radix_tree.py

* Update radix_tree.py

* Update radix_tree.py

Co-authored-by: Alex de la Cruz <alex@Alexs-MacBook-Air.local>
Co-authored-by: Christian Clauss <cclauss@me.com>
2022-10-31 14:14:33 +01:00
Si Lam
ca923389c0
Description of Double hasing (#6467)
* Description of DOuble hasing

* Fix sheebang

* Update double_hash.py

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

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

* Update double_hash.py

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-10-30 11:25:51 +01:00
Andrey
1550731cb7
Remove file-level flake8 suppression (#7844)
* Remove file-level flake8 suppression

* updating DIRECTORY.md

* Fix tests

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2022-10-29 22:45:21 +02:00
Anshraj Shrivastava
efb4a3aee8
added algo for finding permutations of an array (#7614)
* Add files via upload

* Delete permutations.cpython-310.pyc

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

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

* Update permutations.py

* Update permutations.py

* Add files via upload

* Delete permutations.py

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

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

* Update permutations.py

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

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

* Update permutations.py

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

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

* Update permutations.py

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

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

* Update data_structures/arrays/permutations.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update permutations.py

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

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

* Update permutations.py

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

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

* Update data_structures/arrays/permutations.py

Co-authored-by: Chris O <46587501+ChrisO345@users.noreply.github.com>

* Update permutations.py

* Update permutations.py

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

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

* Update permutations.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: Chris O <46587501+ChrisO345@users.noreply.github.com>
2022-10-29 15:29:15 +02:00
Andrey
584e743422
Fix yesqa hook (#7843)
* fix yesqa hook

* Remove redundant noqa

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2022-10-29 15:07:02 +02:00
Christian Clauss
19bff003aa
Adopt Python >= 3.8 assignment expressions using auto-walrus (#7737)
* Adopt Python >= 3.8 assignment expressions using auto-walrus

* updating DIRECTORY.md

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

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

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-10-28 15:54:54 +02:00
Caeden Perelli-Harris
25757e697c
Binary tree path sum (#7748)
* feat: Implement binary tree path sum (#7135)

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

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

* Update data_structures/binary_tree/binary_tree_path_sum.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* refactor: Rename `dfs` to `depth_first_search`

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2022-10-27 23:03:01 +02:00
Caeden Perelli-Harris
61eedc16c3
Remove useless code in doctests (#7733)
* refactor: Fix matrix display deprecation

* refactor: Remove useless `print` and `pass` statements

* revert: Replace broken doctests

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

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

* revert: Fix failing doctests

* chore: Satisfy pre-commit

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-10-27 22:52:00 +02:00
Caeden Perelli-Harris
9bba42eca8
refactor: Indent ... for visual purposes (#7744) 2022-10-27 19:42:30 +02:00
Shubham Kondekar
3448ae5cec
[Binary Tree] Different views of binary tree added (#6965)
* Different views of binary tree added

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

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

* mypy errors resolved

* doc test for remaining functions

* Flake8 comments resolved

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

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

* Example moved in if block

* doctest cases added

* Cases from if block removed

* Update data_structures/binary_tree/diff_views_of_binary_tree.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update data_structures/binary_tree/diff_views_of_binary_tree.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* PR Comments resolved

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

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

* flake8 warning resolved

* Changes revered

* flake8 issue resolved

* Put the diagrams just above the doctests

* Update diff_views_of_binary_tree.py

* Update diff_views_of_binary_tree.py

* I love mypy

* [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>
2022-10-17 22:30:01 +02:00
CenTdemeern1
04698538d8
Misc fixes across multiple algorithms (#6912)
Source: Snyk code quality
Add scikit-fuzzy to requirements

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
2022-10-16 10:55:38 +05:30
Caeden
c94e215c8d
types: Update binary search tree typehints (#7197)
* types: Update binary search tree typehints

* refactor: Don't return `self` in `:meth:insert`

* test: Fix failing doctests

* Apply suggestions from code review

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
2022-10-16 00:51:23 +02:00
Caeden
a652905b60
Add Flake8 comprehensions to pre-commit (#7235)
* ci(pre-commit): Add ``flake8-comprehensions`` to ``pre-commit`` (#7233)

* refactor: Fix ``flake8-comprehensions`` errors

* fix: Replace `map` with generator (#7233)

* fix: Cast `range` objects to `list`
2022-10-15 19:29:42 +02:00
Caeden
98a4c24878
feat: Binary tree node sum (#7020) (#7162)
* feat: Binary tree node sum (#7020)

* feat: Sum of all nodes in binary tree explanation (#7020)

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

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

* Update data_structures/binary_tree/binary_tree_node_sum.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* refactor: Change replace method with `__iter__` overriding (#7020)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2022-10-15 14:58:09 +02:00
Caeden
6e69181d1f
refactor: Replace list() and dict() calls with literals (#7198) 2022-10-15 06:37:03 +05:30
Caeden
2058775005
refactor: Make code more understandable (#7196)
* refactor: Make code more understandable

* [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>
2022-10-15 00:25:15 +02:00
Md Mahiuddin
26fe4c6539
Remove extra Semicolon (#7152) 2022-10-14 09:20:40 +02:00
Caeden
4d0c830d2c
Add flake8 pluin flake8 bugbear to pre-commit (#7132)
* ci(pre-commit): Add ``flake8-builtins`` additional dependency to ``pre-commit`` (#7104)

* refactor: Fix ``flake8-builtins`` (#7104)

* fix(lru_cache): Fix naming conventions in docstrings (#7104)

* ci(pre-commit): Order additional dependencies alphabetically (#7104)

* fix(lfu_cache): Correct function name in docstring (#7104)

* Update strings/snake_case_to_camel_pascal_case.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update data_structures/stacks/next_greater_element.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update digital_image_processing/index_calculation.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update graphs/prim.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update hashes/djb2.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* refactor: Rename `_builtin` to `builtin_` ( #7104)

* fix: Rename all instances (#7104)

* refactor: Update variable names (#7104)

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

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

* ci: Create ``tox.ini`` and ignore ``A003`` (#7123)

* revert: Remove function name changes (#7104)

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

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

* Rename tox.ini to .flake8

* Update data_structures/heap/heap.py

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>

* refactor: Rename `next_` to `next_item` (#7104)

* ci(pre-commit): Add `flake8` plugin `flake8-bugbear` (#7127)

* refactor: Follow `flake8-bugbear` plugin (#7127)

* fix: Correct `knapsack` code (#7127)

* [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>
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
2022-10-13 18:03:06 +02:00
Caeden
d5a9f649b8
Add flake8-builtins to pre-commit and fix errors (#7105)
Ignore `A003`

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: Dhruv Manilawala <dhruvmanila@gmail.com>
2022-10-13 19:53:59 +05:30
GURNEET SINGH
e661b98829
Binary Search Tree Inorder Traversal Algorithm (#6840)
* Binary Search Tree Inorder Traversal

* updating DIRECTORY.md

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

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

* Binary Search Tree Inorder Traversal v2

* Binary Search Tree Inorder Traversal

* Binary Search Tree Inorder Traversal

* Update inorder_tree_traversal_2022.py

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

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

* Update inorder_tree_traversal_2022.py

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

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

* Update inorder_tree_traversal_2022.py

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

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

* Update data_structures/binary_tree/inorder_tree_traversal_2022.py

* Update data_structures/binary_tree/inorder_tree_traversal_2022.py

* Updated

* Updated

* Update inorder_tree_traversal_2022.py

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

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

* Update inorder_tree_traversal_2022.py

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

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

* Update data_structures/binary_tree/inorder_tree_traversal_2022.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Updated and removed print statement

removed the print from inorder function

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

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

Co-authored-by: github-actions <${GITHUB_ACTOR}@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>
2022-10-13 14:09:01 +02:00
Caeden
07e991d553
Add pep8-naming to pre-commit hooks and fixes incorrect naming conventions (#7062)
* ci(pre-commit): Add pep8-naming to `pre-commit` hooks (#7038)

* refactor: Fix naming conventions (#7038)

* Update arithmetic_analysis/lu_decomposition.py

Co-authored-by: Christian Clauss <cclauss@me.com>

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

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

* refactor(lu_decomposition): Replace `NDArray` with `ArrayLike` (#7038)

* chore: Fix naming conventions in doctests (#7038)

* fix: Temporarily disable project euler problem 104 (#7069)

* chore: Fix naming conventions in doctests (#7038)

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-10-13 00:54:20 +02:00
Saksham Chawla
e272b9d6a4
Add typing to data_structures/queue/queue_on_pseudo_stack.py (#7037)
* Add typing

hacktoberfest

* [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>
2022-10-12 18:44:08 +02:00
Saksham Chawla
aeb933bff5
Add typing to data_structures/hashing/hash_table.py (#7040)
* Update hash_table.py

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

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

* Update hash_table.py

* Update hash_table.py

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-10-12 18:37:00 +02:00
Saksham Chawla
d15bf7d492
Add typing to data_structures/heap/heap_generic.py (#7044)
* Update heap_generic.py

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

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

* Update heap_generic.py

* Update heap_generic.py

* Update heap_generic.py

* Update heap_generic.py

* Update heap_generic.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>
2022-10-12 18:35:31 +02:00
pre-commit-ci[bot]
756bb268eb
[pre-commit.ci] pre-commit autoupdate (#6629)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/psf/black: 22.6.0 → 22.8.0](https://github.com/psf/black/compare/22.6.0...22.8.0)
- [github.com/asottile/pyupgrade: v2.37.0 → v2.38.2](https://github.com/asottile/pyupgrade/compare/v2.37.0...v2.38.2)
- https://gitlab.com/pycqa/flake8https://github.com/PyCQA/flake8
- [github.com/PyCQA/flake8: 3.9.2 → 5.0.4](https://github.com/PyCQA/flake8/compare/3.9.2...5.0.4)
- [github.com/pre-commit/mirrors-mypy: v0.961 → v0.981](https://github.com/pre-commit/mirrors-mypy/compare/v0.961...v0.981)
- [github.com/codespell-project/codespell: v2.1.0 → v2.2.1](https://github.com/codespell-project/codespell/compare/v2.1.0...v2.2.1)

* Fix a long line

* Update sol1.py

* Update sol1.py

* lambda_

* Update multi_level_feedback_queue.py

* Update double_ended_queue.py

* Update sequential_minimum_optimization.py

* Update .pre-commit-config.yaml

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2022-10-03 22:00:45 +02:00
C21
81e30fd33c
Fix Max Fenwick Tree (#6328) 2022-09-14 09:24:55 +01:00
AmirMohammad Hosseini Nasab
f31fa4ea7e
Fenwick Tree (#6319)
* Enhance fenwick_tree.py

* Change update to add in fenwick_tree.py

* Some changes

* Fix bug

* Add O(N) initializer to FenwickTree

* Add get method to Fenwick Tree

* Change tree in Fenwick Tree

* Add rank query to FenwickTree

* Add get_array method to FenwickTree

* Add some tests

* Update data_structures/binary_tree/fenwick_tree.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update data_structures/binary_tree/fenwick_tree.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update data_structures/binary_tree/fenwick_tree.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* change `List` to `list`

Co-authored-by: Christian Clauss <cclauss@me.com>
2022-08-16 19:38:33 +02:00
AmirMohammad Hosseini Nasab
f46ce47274
Add Max Fenwick Tree (#6298)
* Add `MaxFenwickTree`

* Reformat code style

* Fix type hints

* Fix type hints again

* Complete docstring

* Complete docstring

* Fix typo in file name

* Change MaxFenwickTree into 0-based indexing

* Fix Bugs

* Minor fix
2022-08-12 11:12:58 +02:00
Nikos Giachoudis
f7c58e4c4b
Unify primality checking (#6228)
* renames prime functions and occurances in comments

* changes implementation of primality testing to be uniform

* adds static typing as per conventions

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2022-07-11 22:36:57 +08:00
Christian Clauss
b75a7c77f8
pre-commit autoupdate: pyupgrade v2.34.0 -> v2.37.0 (#6245)
* pre-commit autoupdate: pyupgrade v2.34.0 -> v2.37.0

* pre-commit run --all-files
2022-07-11 10:19:52 +02:00
Vardhaman
2d5dd6f132
MAINT: Updated f-string method (#6230)
* MAINT: Used f-string method

Updated the code with f-string methods wherever required for a better and cleaner understanding of the code.

* Updated files with f-string method

* Update rsa_key_generator.py

* Update rsa_key_generator.py

* Update elgamal_key_generator.py

* Update lru_cache.py

I don't think this change is efficient but it might tackle the error as the error was due to using long character lines.

* Update lru_cache.py

* Update lru_cache.py

Co-authored-by: cyai <seriesscar@gmail.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2022-07-07 16:34:07 +02:00
Omkaar
dbee5f072f
Improve code on f-strings and brevity (#6126)
* Update strassen_matrix_multiplication.py

* Update matrix_operation.py

* Update enigma_machine2.py

* Update enigma_machine.py

* Update enigma_machine2.py

* Update rod_cutting.py

* Update external_sort.py

* Update sol1.py

* Update hill_cipher.py

* Update prime_numbers.py

* Update integration_by_simpson_approx.py
2022-05-13 20:51:44 +08:00
Shuangchi He
e1ec661d4e
Fix some typos (#6113)
* Fix some typos.

* Update volume.py

Co-authored-by: John Law <johnlaw.po@gmail.com>
2022-05-01 18:44:23 +08:00
varopxndx
10d0e4ecbf
docs: Fix quicksort & binary tree traversal doc (#4878)
* Fix quicksort doc

* add binary tree traversals doc

* Add link to the reference

* Fix job

* Change url

* Update binary_tree_traversals.md

* Update normal_distribution_quick_sort.md

* Update normal_distribution_quick_sort.md

Co-authored-by: John Law <johnlaw.po@gmail.com>
2022-04-29 01:05:21 +08:00
Christian Clauss
1ae5abfc3c
Replace typing.optional with new annotations syntax (#5829)
* Replace typing.optional with new annotations syntax

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2021-11-17 04:43:02 +01:00
Dylan Buchi
e7381b513b
[mypy] Fix type annotations in data_structures/stacks/next_greater_element.py (#5763)
* Fix type annotations in next_greater_element.py

* Refactor next_greater_element.py
2021-11-05 20:45:37 +01:00
Dylan Buchi
7a605766fe
[mypy] Fix type annotations in data_structures/binary_tree/red_black_tree.py (#5739)
* [mypy] Fix type annotations in red_black_tree.py

* Remove blank lines

* Update red_black_tree.py
2021-11-04 16:38:43 +01:00
Dylan Buchi
331fe6d3bc
[mypy] Fix type annotations in data_structures/binary_tree/lowest_common_ancestor.py (#5757)
* Fix type annotations in lowest_common_ancestor.py

* Refactor line 53 in lowest_common_ancestor.py
2021-11-03 21:34:08 +01:00
Dylan Buchi
24731b078c
[mypy] fix type annotations in data_structures/queue/circular_queue_linked_list.py (#5749)
* [mypy] fix type annotations in circular_queue_linked_list

* Remove 10 blank lines

Co-authored-by: Christian Clauss <cclauss@me.com>
2021-11-02 11:09:46 +01:00
Edward Nuno
94f38dd88c
[mypy] Fix type annotations for linked_stack.py (#5576)
* Fix type annotations for linked_stack.py

* Replace Optional with inline union type

* Rename linked_stack to stack_with_singly_linked_list

* Rename stack_using_dll to stack_with_doubly_linked_list

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2021-10-31 17:03:03 +01:00
Dylan Buchi
7488c5070e
Fix type annotations in randomized_heap.py (#5704) 2021-10-31 11:49:34 +01:00
Dylan Buchi
99983c91ca
[mypy] Add/fix type annotations in data_structures/heap/skew_heap.py (#5634)
* Add abstract base class Comparable

* [mypy] Fix type annotations (strict mode)

* Fix a typo

* Remove Comparable class and set bound to bool
2021-10-31 09:38:24 +01:00
Dylan Buchi
678535b5c8
[mypy] Fix type annotations in non_recursive_segment_tree (#5652) 2021-10-30 21:43:48 +02:00
Dylan Buchi
0590d736fa
[mypy] Fix type annotations in wavelet_tree.py (#5641)
* [mypy] Fix type annotations for wavelet_tree.py

* fix a typo
2021-10-28 22:53:02 +02:00
Christian Clauss
477cc3fe59
Add pyupgrade to pre-commit (#5638)
* Add pyupgrade to pre-commit

* Remove unused imports

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2021-10-28 16:45:59 +02:00
Víctor A. Rodríguez
70368a757e
Implement Circular Queue using linked lists. Fixes TheAlgorithms#5361 (#5587)
* CircularQueueLinkedList: empty list, trivial implementation TheAlgorithms#5361

* CircularQueueLinkedList: single element list TheAlgorithms#5361

* CircularQueueLinkedList: refactor, no que empty attribute TheAlgorithms#5361

* CircularQueueLinkedList: refactor TheAlgorithms#5361

* CircularQueueLinkedList: changed internal data structure to use double linked list TheAlgorithms#5361

* CircularQueueLinkedList: enqueue test cases added TheAlgorithms#5361

* CircularQueueLinkedList: track full queue TheAlgorithms#5361

* CircularQueueLinkedList: adding functions description TheAlgorithms#5361

* CircularQueueLinkedList: type hints TheAlgorithms#5361

* CircularQueueLinkedList: algorithm explanation TheAlgorithms#5361

* CircularQueueLinkedList: missing type hints TheAlgorithms#5361

* CircularQueueLinkedList: more missing type hints TheAlgorithms#5361

* Update data_structures/queue/circular_queue_linked_list.py

Co-authored-by: John Law <johnlaw.po@gmail.com>
2021-10-28 22:43:24 +08:00