Commit Graph

291 Commits

Author SHA1 Message Date
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
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
Dylan Buchi
8285913e81
[mypy] Fix and add type annotations (#5618) 2021-10-27 11:45:33 +08:00
Edward Nuno
9a03919052
[mypy] Fix type annotations for stack_using_dll.py (#5577)
* Fix mypy annotations for stack_using_dll.py

* Replace Optional with inline union type
2021-10-26 21:12:46 +02:00
Edward Nuno
c0ed031b3f
Fix type annotations for stack.py (#5566) 2021-10-26 20:33:08 +02:00
Limbad Yash
80a885c975
Update pop function (#5544)
* 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>
2021-10-23 15:18:09 +02:00
Dylan Buchi
20e09c3ec2
[mypy] Add type annotations for linked queue in data structures (#5533)
* [mypy] Add/fix type annotations for linked queue in data_structures

* add return type annotation to __iter__

* Add more readable syntax
2021-10-23 11:56:58 +02:00
Edward Nuno
11ec2fd3fb
[mypy] Fix type annotations for trie.py (#5022)
* 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>
2021-10-23 01:21:41 +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
Sherman Hui
b373c991f6
[mypy] fix: fix mypy error in trie.py(#5516) 2021-10-22 11:40:17 +08:00
Sherman Hui
9153db2d27
[mypy] fix: fix mypy error in singly_linked_list.py (#5517)
The list comprehension shortcut was implicitly expecting a return
value causing a mypy error since `insert_tail` doesn't return a value
2021-10-22 11:39:18 +08:00
Benjamín García Roqués
2e955aea46
Replace double_ended_queue.py (#5429)
* Add deque_from_scratch.py

* added deque_from_scratch.py

* add extend, extendleft and make comparison

* updated operations list

* fix doctest on Deque.__iter__

* pre-commit fix

* time complexity comments, change type hints

* pre-commit fix

* added more doctests
2021-10-21 11:38:04 +08:00
Immiel
2e2e1b656c
singly_linked_list: Added additional documentation, type hints and test cases (#4988)
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.
2021-10-20 16:08:39 +08:00
Alvin Philips
d32d0158a3
Fixed typo (#5439)
Changed it's (it is) to its
2021-10-19 21:39:15 +02:00
scfenton6
abaa0d754b
Add type annotations (#4814) 2021-10-12 00:34:30 +08:00
Parth Satodiya
d324f91fe7
Fix mypy errors for data_structures->linked_list directory files (#4927) 2021-10-07 23:18:23 +08:00
Jogendra Singh
5d02103b27
Fixed #4764 (#4779)
* Fixed #4764

* Fixes #4764
2021-09-24 12:54:38 +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
Ahmed Haj Abdel Khaleq
deb71167e7
[mypy] Fix type annotations for linked_stack.py, evaluate_postfix_notations.py, stack.py in data structures (#4409)
* [mypy] Fix type annotations for linked_stack.py, next_greater_element.py, stack.py

* Reformatted files according to black
2021-05-12 08:22:42 +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
Christian Clauss
69457357e8
binary_tree_traversals.py: Simplify with dataclasses (#4336)
* binary_tree_traversals.py: Simplify with dataclasses

* Update data_structures/binary_tree/binary_tree_traversals.py

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

* Optional["Node"]

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
2021-04-26 10:15:26 +05:30
CarsonHam
61f3119467
Change occurrences of str.format to f-strings (#4118)
* f-string update rsa_cipher.py

* f-string update rsa_key_generator.py

* f-string update burrows_wheeler.py

* f-string update non_recursive_segment_tree.py

* f-string update red_black_tree.py

* f-string update deque_doubly.py

* f-string update climbing_stairs.py

* f-string update iterating_through_submasks.py

* f-string update knn_sklearn.py

* f-string update 3n_plus_1.py

* f-string update quadratic_equations_complex_numbers.py

* f-string update nth_fibonacci_using_matrix_exponentiation.py

* f-string update sherman_morrison.py

* f-string update levenshtein_distance.py

* fix lines that were too long
2021-02-23 11:23:49 +05:30
Hao LI
f680806894
add type hints for avl_tree (#4214)
Co-authored-by: LiHao <leo_how@163.com>
2021-02-22 00:58:17 +01:00
Hao LI
2595cf059d
[mypy] Add/fix type annotations for binary trees in data structures (#4085)
* fix mypy: data_structures:binary_tree

* mypy --strict for binary_trees in data_structures

* fix pre-commit

Co-authored-by: LiHao <leo_how@163.com>
2021-02-05 00:59:38 +08:00
Gaurav Jindal
0728cf1128
Added code to merge two trees (#4121)
* Added code to merge two trees

* Added doctest and type hints

* Added pre-commit
2021-01-18 13:08:22 +05:30
Mark Huang
207ac957ef
[mypy] Add type hints and docstrings to heap.py (#3013)
* Add type hints and docstrings to heap.py

- Add type hints
- Add docstrings
- Add explanatory comments 
- Improve code readability
- Change to use f-string

* Fix import sorting

* fixup! Format Python code with psf/black push

* Fix static type error

* Fix failing test

* Fix type hints

* Add return annotation

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
2020-12-26 08:42:37 +05:30
Maliha
860d4f547b
Create merge_two_lists.py that implements merging of two sorted linked lists (#3874)
* Create merge_two_lists.py that implements merging of two sorted linked lists

* Update merge_two_lists.py

Fixed formatting errors

* Fixed trailing whitespace

* Change name of function to def __str__()

* updating DIRECTORY.md

* Imported classes from singly_linked_list.py

* Update merge_two_lists.py

* Update merge_two_lists.py

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2020-12-03 16:02:48 +01:00
arif599
9c6080a6fc
data_structures/linked_list: Add __str__() function (#3961)
* Adding __str__() function

* Removing white space

* Update data_structures/linked_list/__init__.py

Co-authored-by: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com>

* Adding type hints

* Update __init__.py

* Update __init__.py

* Adding the changes requested

* Updating to fix pre-commit

* Updating __init__.py

* Updating __init__.py

Co-authored-by: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com>
2020-11-28 11:20:18 +05:30
Du Yuanchao
786b32431c
Update infix to postfix (#3817)
* add test to infix_to_postfix_conversion

* fixed pre-commit error

* fixed build error

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-11-02 00:35:31 +08:00
Du Yuanchao
a03b3f763f
Balanced parentheses (#3768)
* Fixed balanced_parentheses.py

* fixed pre-commit

* eliminate is_paired

* remove unused line

* updating DIRECTORY.md

* Update data_structures/stacks/balanced_parentheses.py

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

* Add more test cases

* Update data_structures/stacks/balanced_parentheses.py

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

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2020-10-29 10:39:19 +01:00
Du Yuanchao
1cd8e68537
Update LinkedQueue (#3683)
* update LinkedQueue

* add type hint and rename
2020-10-24 12:16:37 +02:00
Du Yuanchao
c2b7acdf11
Update Linked Stack (#3625)
* update linked_stack

* remove properties

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-10-24 00:16:23 +08:00
Du Yuanchao
5e642607c8
Update doubly linked list (#3619)
* 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>
2020-10-21 22:31:09 +08:00
Christian Clauss
9b95e4f662
Pyupgrade to python3.8 (#3616)
* Upgrade to Python 3.8 syntax

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-10-21 12:46:14 +02:00
Akash G Krishnan
7d84f7fe61
Adding in the evaluate postfix notation using Stack (#2598)
* 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>
2020-10-16 20:45:26 +02:00
Akash G Krishnan
c33b683193
New doubly linkedlist PR: pull/2573 (#3380)
https://github.com/TheAlgorithms/Python/pull/2573 
the second implementation of the Doubly linked list
2020-10-16 15:13:45 +02:00
Anshraj Shrivastava
e035c6164f
add binary_tree_traversals.py to data_structures (#3297)
* add binary_tree_traversals.py to data_structures

I have added some interesting binary tree traversing methods.

* Fixed error

* Update data_structures/binary_tree/binary_tree_traversals.py

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

* Update binary_tree_traversals.py

* Update binary_tree_traversals.py

* Update binary_tree_traversals.py

* Update data_structures/binary_tree/binary_tree_traversals.py

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

* Update binary_tree_traversals.py

* Update binary_tree_traversals.py

* Update binary_tree_traversals.py

* Update binary_tree_traversals.py

* Update binary_tree_traversals.py

* Update binary_tree_traversals.py

* Update binary_tree_traversals.py

* Update binary_tree_traversals.py

* Update binary_tree_traversals.py

* Update binary_tree_traversals.py

* Update data_structures/binary_tree/binary_tree_traversals.py

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

* Update binary_tree_traversals.py

* Update binary_tree_traversals.py

* Update data_structures/binary_tree/binary_tree_traversals.py

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

* Update data_structures/binary_tree/binary_tree_traversals.py

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

* Update binary_tree_traversals.py

* Update data_structures/binary_tree/binary_tree_traversals.py

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

* Update binary_tree_traversals.py

* Doctests and type hints

* Add spaces

* Update binary_tree_traversals.py

* black exclude data_structures/binary_tree/binary_tree_traversals.py

* Add spaces again

* Update binary_tree_traversals.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-10-15 13:09:59 +02:00
Phil Bazun
e3c07f987f
Add skew heap data structure. (#3238)
* Add skew heap data structure.

* fixup! Add skew heap data structure.

* fixup! Add skew heap data structure.

* fixup! Add skew heap data structure.

* Add tests.

* Add __iter__ method.

* fixup! Add __iter__ method.
2020-10-14 12:35:53 +02:00
Susmith98
dc069580b9
Added binary tree mirror algorithm (#3159)
* Added binary tree mirror algorithm

* Minor changes

* Resolved comments

* Minor Changes

* resolved comments and updated doctests

* updated doctests

* updating DIRECTORY.md

Co-authored-by: svedire <VedireSusmith_Reddy@intuit.com>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-10-14 12:21:15 +02:00