* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* [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>
* Updated Pop function
Added underflow condition
* Update Pop Function
Added condition to check underflow of stack
* Update stack.py
* if not self.stack: raise StackUnderflowError
* Add doctests
* StackUnderflowError
* ..., not ....
* Update stack.py
Co-authored-by: Christian Clauss <cclauss@me.com>
* Fix type annotations for trie.py
* Add strict type annotations to trie.py
Annotate return type for all functions and type for "nodes"
* updating DIRECTORY.md
* Format trie.py
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
* 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>
This is a followup to https://github.com/TheAlgorithms/Python/pull/4973#issuecomment-933117382
As per given suggestion, I've added type hints to certain methods that don't have them. I have also added documentation and example doctests as a usage example for (most of) those that don't have them.
I have also added another test case following the previous test case's format. I noticed that the existing test case from previous pull request might be redundant with the ones I've made, so I decided to create a specific situation where the linked list would have to keep different kinds of data types for each node, in `test_singly_linked_list_2` test function.
Some minor changes in strings has been done to keep things consistent with other parts of the document. If it is undesirable, please let me know.
* 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>
* update doubly linked list
* reformat code
add more test
* add test to iter
* updating DIRECTORY.md
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
* Create evaluate_postfix_notations.py
Adding in the evaluate postfix notation using Stacks
one of the common use with simple stack question
creating a new file for the data structure of stacks
* Create evaluate_postfix_notations.py
Adding in the evaluate postfix notation using Stacks
one of the common use with simple stack question
creating a new file for the data structure of stacks
* Delete evaluate_postfix_notations.py
* Evaluate postfix expression stack clean approach
Sending in the PR again as the Previous request failed in pre commit
* Update evaluate_postfix_notations.py
* Update evaluate_postfix_notations.py
Made changes as per the required for fixing the failing pre-commits.
* Update evaluate_postfix_notations.py
Made changes as suggested by @cclauss
* Update evaluate_postfix_notations.py
fixed pre-commit fails
* Update evaluate_postfix_notations.py
fixing pre-commit fails
* Update evaluate_postfix_notations.py
Deleted trailing white spaces causing pre-commits to fail
* Update data_structures/stacks/evaluate_postfix_notations.py
Co-authored-by: Christian Clauss <cclauss@me.com>
* Update data_structures/stacks/evaluate_postfix_notations.py
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
* chore: update print_reverse helper method
Use a generator expression instead of slicing
`elements_list` to improve the space and time complexity
of `make_linked_list` to O(1) space and O(n) time
by avoiding the creation a shallow copy of `elements_list`.
* fix: add type checking and argument typing
Add argument typing to all methods in `print_reverse`
Add doctest to helper function `make_linked_list` and
basic edge case tests to `print_reverse`
* test: add `print_reverse` test
Fix doctest syntax and remove edge case tests that are covered
by typed arguments.
Add `print_reverse` test that expects the correct values are printed
out by adding a `test_print_reverse_output` helper function.
* format code
Co-authored-by: shellhub <shellhub.me@gmail.com>
* added an algorithm which checks a linked list for loops and returns true if one is found
* added doctests and clarified meaning of loop
* Define Node.__iter__()
* Update and rename has_loop.py to has_duplicate_data.py
* Update has_duplicate_data.py
* Update has_duplicate_data.py
* Update and rename has_duplicate_data.py to has_loop.py
* Update has_loop.py
Co-authored-by: Christian Clauss <cclauss@me.com>
* Create alternate_disjoint_set.py
This code implements a disjoint set using Lists
with added heuristics for efficiency
Union by Rank Heuristic and Path Compression
* Update alternate_disjoint_set.py
Added typehints, doctests and some suggested variable name change
* Update alternate_disjoint_set.py
* Formatted with Black
* More formatting
* Formatting on line 28
* Error in Doctest
* Doctest Update in alternate disjoint set
* Fixed build error
* Fixed doctest
* fixes: #2172
* fixes: #2172
* Added docstrings and type of parameters
* fixed error
* Added type hints
* made changes
* removed capital letters from function name
* Added type hints
* fixed bulid error
* modified comments
* fixed build error
* adding static type checking to basic_binary_tree.py
* Add static type checking to functions with None return type
* Applying code review comments
* Added missing import statement
* fix spaciing
* "cleaned up depth_of_tree"
* Add doctests and then streamline display() and is_full_binary_tree()
* added static typing to lazy_segment_tree.py
* added missing import statement
* modified variable names for left and right elements
* added static typing to lowest_common_ancestor.py
* fixed formatting
* modified files to meet style guidelines, edited docstrings and added some doctests
* added and fixed doctests in lazy_segment_tree.py
* fixed errors in doctests
Co-authored-by: Christian Clauss <cclauss@me.com>
* created dijkstra's two stack algorithm
* Made changes to dijkstras two stack algorithm for documentation and
testing purposes.
* Made changes to dijkstras two stack algorithm for documentation and
testing purposes.
* Fixed Grammar Mistake
* Added Explanation Reference
* Imported stack instead of using my own
Changed a few minor things.
* Imported stack instead of using my own
Changed a few minor things.
* Update data_structures/stacks/dijkstras_two_stack_algorithm.py
Co-authored-by: Christian Clauss <cclauss@me.com>
* Update dijkstras_two_stack_algorithm.py
Co-authored-by: Christian Clauss <cclauss@me.com>
* adding static type checking to basic_binary_tree.py
* Add static type checking to functions with None return type
* Applying code review comments
* Added missing import statement
* fix spaciing
* "cleaned up depth_of_tree"
* Add doctests and then streamline display() and is_full_binary_tree()
Co-authored-by: Christian Clauss <cclauss@me.com>
* Fix doubly linked list algorithm
* Fix bug with insert_at_tail method
Create __str__() method for Node class and LinkedList class
* Simplify __str__() of LinkedList
Returns empty string if there are no elements in the list
* Fix description
* Update __init__.py
please add a function to get length of linked list
* Update __init__.py
* Update doubly_linked_list.py
all size function lo doubly linked list class
* prime number _better method
* comments
* Updated init.py 2
made it more pythonic
* updated length function
* commnet in linked_list construtor
* Update data_structures/linked_list/__init__.py
accepecting changes
Co-authored-by: Christian Clauss <cclauss@me.com>
* Update data_structures/linked_list/__init__.py
Co-authored-by: Christian Clauss <cclauss@me.com>
* Update __init__.py
* Revert changes to doubly_linked_list.py
* Revert changes to prime_check.py
Co-authored-by: Christian Clauss <cclauss@me.com>
* Tighten up psf/black and flake8
* Fix some tests
* Fix some E741
* Fix some E741
* updating DIRECTORY.md
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
* Precision must be a nonnegative integer
* fixup! Format Python code with psf/black push
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
* added __len__ function
Added a function to count number of nodes in linked list
* Updated __len__ method
used snake_case instead of camel case
* Add tests to __len__()
Co-authored-by: Christian Clauss <cclauss@me.com>
* Fix psf/black issues than fail the build
* fixup! Format Python code with psf/black push
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
* enhanced segment tree implementation and more pythonic
enhanced segment tree implementation and more pythonic
* add doctests for segment tree
* add type annotations
* unified processing sum min max segment tre
* delete source encoding in segment tree
* use a generator function instead of returning
* add doctests for methods
* add doctests for methods
* add doctests
* fix doctest
* fix doctest
* fix doctest
* fix function parameter and fix determine conditions
* With all suggested changes ✅
possibly covered all the recommended guidelines
* Updated with both slow and faster algorithms
possibally covered all the recomendations
* removed the time comparision part!
* Update data_structures/stacks/next_greater_element.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 data_structures/stacks/next_greater_element.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>
* Add benchmark using timeit
https://docs.python.org/3/library/timeit.html
The performance delta between these two implementation is quite small...
```
next_greatest_element_slow(): 1.843442126
next_greatest_element(): 1.828941414
```
* Optimize slow() to create fast() - Three algorithms in the race
Three algorithms in the race
* Use a bigger test array with floats, negatives, zero
* Setup import next_greatest_element_fast
Co-authored-by: Christian Clauss <cclauss@me.com>
* Fix rehashing function will not call insert_data function
* Fix typo
* Update loop syntax instead of allocating a list
Co-Authored-By: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
* spelling corrections
* review
* improved documentation, removed redundant variables, added testing
* added type hint
* camel case to snake case
* spelling fix
* review
* python --> Python # it is a brand name, not a snake
* explicit cast to int
* spaces in int list
* "!= None" to "is not None"
* Update comb_sort.py
* various spelling corrections in documentation & several variables naming conventions fix
* + char in file name
* import dependency - bug fix
Co-authored-by: John Law <johnlaw.po@gmail.com>
* enhance swapping code in link
* heapify do not recursive
* fix
* fix identifier and add test
* typing.Any and LinkedList instead of Linkedlist
* typing.Any and LinkedList instead of Linkedlist
* Code Upload
* Code Upload
* Delete n_possible_bst
* Find the N Possible Binary Tree and Binary Tree from given Nth Number of Node.
* Update in Test
* Update and rename n_possible_bst.py to number_of_possible_binary_trees.py
Co-authored-by: Christian Clauss <cclauss@me.com>
* Stack using double linked list
* Test with doctests
* Update stack_using_dll.py
* Update stack_using_dll.py
* Update stack_using_dll.py
Co-authored-by: Christian Clauss <cclauss@me.com>