* 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