Commit Graph

99 Commits

Author SHA1 Message Date
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
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
aryan1165
eaa87bd791
Made binary tree memory-friendly using generators based travels. Fixes (#9208)
#8725
2023-10-01 04:43:48 -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
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
roger-sato
0b0214c42f
Handle empty input case in Segment Tree build process (#8718) 2023-07-31 11:46:30 -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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Dylan Buchi
bf6db32ec2
[mypy] Fix type annotations for binary tree traversals in data structures (#5556)
* [mypy] Fix type annotations for binary tree traversals in data structures

* Change variable name and update level_order_1 to use a deque

Using a deque instead of a list here, because since we are removing from the beginning of the list, the deque will be more efficient.

* remove duplicate function

* Update data_structures/binary_tree/binary_tree_traversals.py

Co-authored-by: John Law <johnlaw.po@gmail.com>

* fix function name at line 137

* Update data_structures/binary_tree/binary_tree_traversals.py

Co-authored-by: John Law <johnlaw.po@gmail.com>

* Update data_structures/binary_tree/binary_tree_traversals.py

Co-authored-by: John Law <johnlaw.po@gmail.com>

* Remove type alias and use the new syntax

* Update data_structures/binary_tree/binary_tree_traversals.py

Co-authored-by: John Law <johnlaw.po@gmail.com>

* Remove prints inside functions and return lists

Co-authored-by: John Law <johnlaw.po@gmail.com>
2021-10-28 22:05:31 +08:00
Sherman Hui
629848e372
[mypy] Fix type annotations in data_structures/binary_tree (#5518)
* fix: fix mypy errors

Update binary_search_tree `arr` argument to be typed as a list
within `find_kth_smallest` function

Update return type of `merge_two_binary_trees` as both inputs can
be None which means that a None type value can be returned from
this function

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2021-10-22 16:07:05 +02:00
Alvin Philips
d32d0158a3
Fixed typo (#5439)
Changed it's (it is) to its
2021-10-19 21:39:15 +02:00
Christian Clauss
cecf43d648
Pyupgrade to Python 3.9 (#4718)
* Pyupgrade to Python 3.9

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2021-09-07 13:37:03 +02:00
Aniruddha Bhattacharjee
b743e44259
Wavelet tree (#4267)
* Added the matrix_exponentiation.py file in maths directory

* Implemented the requested changes

* Update matrix_exponentiation.py

* resolve merge conflict with upstream branch

* add new line at end of file

* add wavelet_tree

* fix isort issue

* updating DIRECTORY.md

* fix variable names in wavelet_tree and correct typo

* Add type hints and variable renaming

* Update data_structures/binary_tree/wavelet_tree.py

Add doctests to placate the algorithm-bot, thanks to @cclauss.

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

* Move doctest to individual functions and reformat code

* Move common test array to the global scope and reuse in tests

* MMove test array to global scope and minor linting changes

* Correct the failing pytest tests

* MUse built-in list for type annotation

* Update wavelet_tree.py

* types-requests

* updating DIRECTORY.md

* Update wavelet_tree.py

* # type: ignore

* # type: ignore

* Update decrypt_caesar_with_chi_squared.py

* ,

* Update decrypt_caesar_with_chi_squared.py

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Aniruddha Bhattacharjee <aniruddha@Aniruddhas-MacBook-Air.local>
2021-06-08 22:49:33 +02:00
Dhruv Manilawala
6f21f76696
fix(ci): Update pre-commit hooks and apply new black (#4359)
* fix(ci): Update pre-commit hooks and apply new black

* remove empty docstring
2021-04-26 07:46:50 +02:00