Commit Graph

170 Commits

Author SHA1 Message Date
Sailesh Shrestha
3815a97575
Add all_construct dynamic programming implementation (#5626)
* Add all_construct dynamic programming implementation

* all_construct: remove the main function

* all_construct: Add type hints

* all_construct: changed map to list comprehension,fix mutable default arguments

* all_construct: fixed type hints

* all_construct: cleaner code for initializing word_bank argument

* all_construct: added an import for annotations

* all_construct: added None in the argument with word_bank

* all_construct: fixed a type hint

* all_construct: Fixed some more type hints
2021-11-04 16:18:38 +01:00
Maarten
868c2fa0a8
Rewrite fibonacci.py (#5665) (#5677)
* Removed doctest call

* Removed 0 and 1 append to `fib_array`

* Moved fibonacci sequence logic into `calculate`

* Refactored `get` to generate missing numbers

* Renamed `fib_array` to `sequence`

* Renamed `number` to `index`

* Refactored `get` to only return sequence to `index`

* Moved main block into function

* Added documentation to `get`

* Added missing type hints

* Fixed doctest error in `get` docstring

* Moved calculate logic into get

* Reformatted with black

* Fixed wrong generation range
2021-10-31 22:19:44 +08:00
imp
c1b15a86ba
[mypy] Fix type annotations for dynamic programming (#4687)
* Fix mypy error for knapsack.py

* Fix mypy error for longest_increasing_subsequence

* Fix mypy error for fractional_knapsack_2.py
2021-09-03 11:49:23 +02:00
Aswin Murali
3acca3d1d1
Fix type annotations for integer_partition.py #4052 (#4689) 2021-08-30 10:06:59 +02:00
Lakshay Akula
cb0a5480a7
Add catalan_numbers.py (#4455)
Reviewed by @mrmaxguns. This is an implementation of Catalan Numbers.
2021-05-31 19:55:01 -05:00
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
Kanak
677d48d6c0
Rename coin_change.py to minimum_coin_change.py (#4108) 2021-01-11 16:55:15 +05:30
Alex Joslin
e7ab06f5de
Implemented minimum steps to one using tabulation. (#3911)
* Implemented minimum steps to one using tabulation.

* Update minimum_steps_to_one.py

Made the parameter "n" more descriptive.  Changed it to number

* `n` to `number`

Co-authored-by: John Law <johnlaw.po@gmail.com>
2020-12-09 17:22:07 +08:00
Himadri Ganguly
46af42d47a
Fix coin change (#2571)
* Removed unused variable m.

* Doctests are modified to match functions.

* Added condition for negative values.

* Fixed white-space around operator.

* Fixed W293 blank line contains white-space error.

* Update dynamic_programming/coin_change.py

Co-authored-by: Tapajyoti Bose <44058757+ruppysuppy@users.noreply.github.com>

* Fixed error in code.

* Fixed whited spacing.

* Fixed PEP8 error.

* Added more test cases for coin change problem.

* Removed extra test for negetive value.

Co-authored-by: Tapajyoti Bose <44058757+ruppysuppy@users.noreply.github.com>
2020-10-24 00:55:13 +08:00
Dhruv
48357cea5b
Add __init__.py files in all the directories (#2503) 2020-09-28 19:42:36 +02:00
Christian Clauss
9200a2e543
from __future__ import annotations (#2464)
* from __future__ import annotations

* fixup! from __future__ import annotations

* fixup! from __future__ import annotations

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-09-23 13:30:13 +02:00
Du Yuanchao
4d0a8f2355
Optimized recursive_bubble_sort (#2410)
* optimized recursive_bubble_sort

* Fixed doctest error due whitespace

* reduce loop times for optimization

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-09-10 10:31:26 +02:00
Sanders Lin
f0d7879a11
fixed error in factorial.py (#1888)
* Update factorial.py

* updating DIRECTORY.md

* Update dynamic_programming/factorial.py

* Update factorial.py

Co-authored-by: mateuszz0000 <mtszzwdzk@gmail.com>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2020-08-05 13:18:41 +02:00
Christian Clauss
5f4da5d616
isort --profile black . (#2181)
* updating DIRECTORY.md

* isort --profile black .

* Black after

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-07-06 09:44:19 +02:00
Christian Clauss
cd3e8f95a0
isort --profile black --recursive . (#2170)
* isort --profile black --recursive .

* Update codespell.yml

* typo: vertices

* typo: Explanation

* typo: Explanation

* Fix typos
2020-07-06 08:48:18 +05:30
vinayak
2d3d660155
black fixes and Travis CI fixes (#2160)
* black format

* updating DIRECTORY.md

* fixes

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-07-02 20:02:15 +05:30
Tapajyoti Bose
c534e77cb1
Added minimum cost path algorithm (#2135)
* Added maximum path sum for matrix (top left to bottom right)

* Changed maximum cost path to minimum cost path + added video explaination
2020-07-02 14:43:29 +05:30
Christian Clauss
fdc5bee7af
Euler problem 551 sol 1: Reduce McCabe code complexity (#2141)
* Euler problem 551 sol 1: Reduce McCabe code complexity

As discussed in #2128

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-06-22 14:16:12 +02:00
Tapajyoti Bose
23484efdad
Added maximum non-adjacent sum (#2130)
* Added maximum non-adjacent sum

* Bugfix: flake8 test

* Implemented changes (broke tuple unpacking into 2 lines due to flake8 tests)

* Implemented changes v2.0

* Update max_non_adjacent_sum.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-06-17 17:09:29 +02:00
Christian Clauss
9316e7c014
Set the Python file maximum line length to 88 characters (#2122)
* flake8 --max-line-length=88

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-06-16 10:09:19 +02:00
Christian Clauss
1f8a21d727
Tighten up psf/black and flake8 (#2024)
* 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>
2020-05-22 08:10:11 +02:00
Sanders Lin
777ddca2e9
Update fast_fibonacci.py (#1889)
* Update fast_fibonacci.py

* Update fast_fibonacci.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-05-19 19:31:52 +02:00
Christian Clauss
6acd7fb5ce
Wrap lines that go beyond GitHub Editor (#1925)
* Wrap lines that go beyond GiHub Editor

* flake8 --count --select=E501 --max-line-length=127

* updating DIRECTORY.md

* Update strassen_matrix_multiplication.py

* fixup! Format Python code with psf/black push

* Update decision_tree.py

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-05-01 23:36:35 +02:00
Sanders Lin
1c9d4a3929
Update abbreviation.py (#1887) 2020-04-17 20:04:30 +02:00
matkosoric
7f04e5cd34
contribution guidelines checks (#1787)
* 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>
2020-03-04 13:40:28 +01:00
Christian Clauss
652b891a75
Travis CI: Upgrade to Python 3.8 (#1783)
* Travis CI: Upgrade to Python 3.8

* updating DIRECTORY.md

* Tensorflow is not yet compatible with Python 3.8

* Disable k_means_clustering_tensorflow.py

* updating DIRECTORY.md

* Disable gan.py

* updating DIRECTORY.md

* Disable input_data.py

* updating DIRECTORY.md

* pip install a current version of six
2020-02-23 04:23:00 +01:00
onlinejudge95
4866b1330b
Fixes black failures from Previous PR (#1751)
* Fixes black failures from Previous PR

* Fixes equality testing alert

* Fixes call to main() alert

* Fixes unused import
2020-02-13 02:19:41 +05:30
Jimmy Y
1096aa2336
Added DP Solution for Optimal BST Problem (#1740)
* Added code to dynamic_programming directory

* Added doctest

* Elaborated BST

* Small tweaks

* Update optimal_bst.py

* Some touchups

* Fixed doctest

* Update optimal_bst.py

* Update optimal_bst.py

* Update optimal_bst.py

* Rename optimal_bst.py to optimal_binary_search_tree.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-02-11 05:53:26 +01:00
onlinejudge95
6fdd53c676
Fixes LGTM issues (#1745)
* Fixes redefinition of a variable

* Fixes implementing __eq__

* Updates docstring
2020-02-10 22:23:19 +01:00
Christian Clauss
bfcb95b297
Create codespell.yml (#1698)
* fixup! Format Python code with psf/black push

* Create codespell.yml

* fixup! Format Python code with psf/black push
2020-01-18 13:24:33 +01:00
Christian Clauss
28419cf839 pyupgrade --py37-plus **/*.py (#1654)
* pyupgrade --py37-plus **/*.py

* fixup! Format Python code with psf/black push
2020-01-03 22:25:36 +08:00
Christian Clauss
34c808b375 actions/checkout@v2 (#1643)
* actions/checkout@v2

https://github.com/actions/checkout/releases

* fixup! Format Python code with psf/black push
2019-12-26 19:50:12 +08:00
faizan2700
86dbf0a9d3 file iterating_through_submasks.py for given mask is added in dynamic_programming (#1635)
* new file *iterating_through_submasks* is added in dynamic_programming section

* no changes

* *iterating_through_submasks.py is added in dynamic_programming

* iterating_through_submasks is added with doctests

* iterating_through_submasks.py is added in dynamic_programming

* changes made in *iterating_through_submasks.py

* changes made in *iterating_through_submasks.py

* updated
2019-12-18 19:55:12 +05:30
Iqrar Agalosi Nureyza
1af4c02ba6 adding doctests on coin_change.py and fixed some typos (#1337)
* adding doctests on coin_change.py

* fixed some typos

* Update lib.py
2019-12-18 08:35:03 +01:00
GeorgeChambi
9eb50cc223 Improved readability (#1615)
* improved readability

* further readability improvements

* removed csv file and added f
2019-12-07 06:39:59 +01:00
Arun Babu PT
c5fd075f1e Fractional knapsack (#1524)
* Add files via upload

* Added doctests, type hints, f-strings, URLs

* Rename knapsack.py to fractional_knapsack.py

* Rename graphs/fractional_knapsack.py to dynamic_programming/fractional_knapsack_2.py
2019-11-22 22:55:19 +08:00
Christian Clauss
b838f1042c Fix indentation contains tabs (flake8 E101,W191) (#1573) 2019-11-15 23:05:00 -08:00
Christian Clauss
5df8aec66c
GitHub Action formats our code with psf/black (#1569)
* GitHub Action formats our code with psf/black

@poyea Your review please.

* fixup! Format Python code with psf/black push
2019-11-14 19:59:43 +01:00
John Law
a9d5378ce2
Doctest and typing for longest_increasing_subsequence.py (#1526)
* Update longest_increasing_subsequence.py

* Update longest_increasing_subsequence.py

* Format longest_increasing_subsequence.py to PEP8

* Update longest_increasing_subsequence.py
2019-11-05 02:06:16 +08:00
Taufik Algi F
c717f8d860 add max sum contigous subsequence (#1537)
* add max sum contigous subsequence

* fix typo

* Add doctest and type hints

* Create autoblack.yml
2019-10-31 18:45:01 +01:00
John Law
357dbd4ada
Doctest, type hints and bug in LIS_O(nlogn) (#1525)
* Update longest_increasing_subsequence_o(nlogn).py

* Update longest_increasing_subsequence_o(nlogn).py
2019-10-31 01:06:07 +08:00
John Law
1da1ab0773 Improve doctest and comment for maximum sub-array problem (#1503)
* Doctest and comment for maximum sub-array problem

More examples and description for max_sub_array.py

* Update max_sub_array.py

* Update max_sub_array.py

* Fix doctest
2019-10-28 17:44:57 +01:00
Ankur Chattopadhyay
7592cba417 psf/black code formatting (#1421)
* added sol3.py for problem_20

* added sol4.py for problem_06

* ran `black .` on `\Python`
2019-10-22 19:13:48 +02:00
Jigyasa G
ddb094919b Adding doctests for fractional_knapsack.py (#1331)
* Adding doctests for fractional_knapsack.py

* Update fractional_knapsack.py
2019-10-18 08:13:20 +02:00
Jigyasa G
67291a5bce Modified longest_common_ssubsequence.py for successful doctests (#1332) 2019-10-12 02:32:41 +08:00
Jigyasa G
e678879892 Adding doctests for sum_of_subset.py (#1333) 2019-10-12 02:29:50 +08:00
Jigyasa G
ea47ae2932 Adding missing Doctests (#1330)
* Adding doctests in abbreviation

* Adding doctests in fibonacci.py
2019-10-10 00:20:19 +05:00
William Zhang
9eac17a408 psf/black code formatting (#1277) 2019-10-05 10:14:13 +05:00
Maxwell Aladago
2dfe01e4d8 Fully refactored the rod cutting module. (#1169)
* changing typo

* fully refactored the rod-cutting module

* more documentations

* rewording
2019-09-05 08:22:06 +02:00
Rwithik Manoj
d4151bd516 Fix possible error in longest_common_subsequence.py (#1163)
The comparison at line 53 was not checking if (j > 0).
2019-08-31 13:40:50 +02:00
Christian Clauss
47a9ea2b0b
Simplify code by dropping support for legacy Python (#1143)
* Simplify code by dropping support for legacy Python

* sort() --> sorted()
2019-08-19 15:37:49 +02:00
Maxwell Aladago
32aa7ff081 ENH: refactored longest common subsequence, also fixed a bug with the sequence returned (#1142)
* function for the knapsack problem which returns one of the optimal subsets

* function for the knapsack problem which returns one of the optimal subsets

* function for the knapsack problem which returns one of the optimal subsets

* function for the knapsack problem which returns one of the optimal subsets

* function for the knapsack problem which returns one of the optimal subsets

* some pep8 cleanup too

* ENH: refactored longest common subsequence, also fixed a bug with the sequence returned

* renamed function
2019-08-19 09:40:36 +02:00
Maxwell Aladago
5d46a4dd7b ENH: Added a functionality to make it possible to reconstruct an optimal subset for the dynamic programming problem (#1139)
* function for the knapsack problem which returns one of the optimal subsets

* function for the knapsack problem which returns one of the optimal subsets

* function for the knapsack problem which returns one of the optimal subsets

* function for the knapsack problem which returns one of the optimal subsets

* function for the knapsack problem which returns one of the optimal subsets

* some pep8 cleanup too
2019-08-19 07:39:39 +02:00
Sanders Lin
f64b602938 Update max_sub_array.py (#1000)
* Update max_sub_array.py

added another method of computing maximum sum subarray

* Update max_sub_array.py

* Update max_sub_array.py
2019-07-17 18:12:24 +02:00
Jigyasa G
f195d9251c adding factorial (#930)
* adding factorial

* adding doctest

* Update factorial.py
2019-07-17 08:22:08 +02:00
cclauss
2fb3beeaf1 Fix error message and format with python/black (#1025)
@SandersLin Your review please?
2019-07-16 10:56:28 +05:30
Sanders Lin
1e55bfd4da Create climbing_stairs.py (#1002)
a simple dp problem seen on LeetCode:  https://leetcode.com/problems/climbing-stairs/
2019-07-15 18:17:41 +02:00
Sanders Lin
7271c0d64a Update rod_cutting.py (#995)
* Update rod_cutting.py

A hopefully clearer implementation without dependence on global variables.

* Update rod_cutting.py

added doctests

* Update rod_cutting.py

* Update rod_cutting.py
2019-07-13 09:12:54 +02:00
Sanders Lin
7a6ebb85a2 Update edit_distance.py (#1001)
added bottom up method.
2019-07-13 09:10:02 +02:00
Alfonso Rodríguez Pereira
5f991f7740 #315 Renamed all files to snake_case (#993) 2019-07-11 11:16:42 +02:00
cclauss
e6eaa078e2
Pytest the entire repo (#980)
* Pytest the entire repo

* Do each directory for now...

* YAML files hate tabs

* Add more requirements

* pip install opencv-python

* Comment out FTP

* Add pandas and sklearn to requirements

* Comment out FTP, graphs, machine_learning, maths, neural_network, project_euler

* Update .travis.yml

* Comment out Data structures

* if __name__ == "__main__":

* pytest --ignore=

* pytest .

* Update .travis.yml

* pytest . --doctest-modules --ignore=${IGNORE}

* Ignore --ignore because it just hangs
2019-07-10 06:59:39 +02:00
Jigyasa G
65a12fa317 Adding sum of subsets (#929) 2019-07-02 23:23:35 +08:00
Ambuj81
7f4f565e62 subset_generation (#326)
* subset_generation

generate all possible subset of size n of a given array of size r

* Rename subset_generation to subset_generation.py

* Update subset_generation.py

I made all changes I could  . What I mean is I removed all the empty space ....... 
There some comment extra if you feel removing those comments please do so yourself pls provide spacing as it should be

* Create morse_Code_implementation.py

* Any more changes pls let me know
2019-05-26 22:07:40 +05:30
Anup Kumar Panwar
71be23999c refactor 2019-05-26 21:56:10 +05:30
Aditya Haridas Menon
bb29dc55fa Bitmasking and DP added (#705) 2019-03-28 01:59:31 +08:00
pradyotd
98a149e41e Update coin_change.py (#706)
Cleanup PEP-8 , additional comments , using coin_val, instead of range and index.
2019-02-21 00:54:26 +08:00
Anthony Marakis
dc302be505 Create rod_cutting.py (#373) 2019-02-09 08:27:23 +05:30
Ashwek Swamy
39912aed57 Update max_sub_array.py (#597) 2018-11-05 09:31:00 +01:00
Benedikt Werner
6db1994de2 Remove unnecessary loop in matrix_chain_order.py (#564) 2018-10-31 08:31:49 +01:00
Alex Brown
b566055e4b Merge branch 'master' of https://github.com/TheAlgorithms/Python 2018-10-20 14:15:21 -05:00
Srikumar Sastry
94324e91b4 Create FractionalKnapsack.py (#438) 2018-10-19 15:21:40 +02:00
Alex Brown
564179a0ec increment 1 2018-10-19 07:48:28 -05:00
Alex Brown
718b99ae39 increment 1 2018-10-19 07:48:01 -05:00
Parth Shandilya
07451a6ca4
Improved Code and removed warnings (#482)
Improved Code and removed warnings
2018-10-19 13:28:21 +05:30
ParthS007
0856a61859 Remove Multiple Unused Imports and Variable 2018-10-18 02:58:57 +05:30
bharath-123
bd7054ace9
updated testcase
Changed name to __name__. Sorry for the typo!
2018-07-23 13:01:02 +05:30
bharath-123
a9f9062080
Added code for memory function implementation
Added a function which implements knapsack using memory functions. Also I updated the test cases to include test cases for the memory function implementation.
2018-07-23 00:36:53 +05:30
Daniel Ingram
888c51b9d2 Counting integer partitions 2018-03-22 09:33:54 -04:00
cclauss
00a2b90356
Fix Python 2 syntax error in matrix_chain_order.py 2018-03-19 02:48:09 +01:00
shivg7706
1506ac9039 MatrixChainOrder 2018-02-26 17:25:09 +05:30
cclauss
4ee0e620cb Modernize Python 2 code to get ready for Python 3 AGAIN 2018-01-21 08:25:19 +01:00
cclauss
cc5102ab01
noqa to silence flake8 on Python 3 only syntax 2018-01-20 12:33:27 +01:00
ashu01
c9debdbd41 1. Removed ; 2017-12-31 14:36:29 +05:30
cclauss
2ed1bad747
Merge branch 'master' into modernize-python2-code 2017-12-13 16:32:28 +01:00
Harshil
2dcbbd4325
Merge pull request #215 from erdenezul/dp_abbreviation
add abbrevation solution to dp
2017-12-13 13:26:29 +05:30
Harshil
f0addfb2f3
Merge pull request #158 from Sayan97/patch-3
Update minimum_partition.py
2017-11-28 17:06:16 +05:30
cclauss
e31c780d94 Modernize Python 2 code to get ready for Python 3 2017-11-25 12:41:55 +01:00
cclauss
4e06949072 Modernize Python 2 code to get ready for Python 3 2017-11-25 10:23:50 +01:00
Erdenezul
69f009e0a5 add abbrevation solution to dp 2017-11-21 15:28:55 +08:00
Erdenezul
3c4c7eb2aa refactor longest common subsequence problem 2017-11-01 15:04:55 +08:00
Erdenezul
53ce9b8068 fix typo 2017-10-25 15:58:46 +08:00
Erdenezul
96536ad761 add coin change problem 2017-10-25 09:56:48 +08:00
Sarot Busala
edaa2c1588 Floyd Warshall Algorithm
upload simple Floyd-Warshall Algorithm (No path stored)
2017-10-20 16:26:07 +07:00
Harshil
a093f55d63 Merge pull request #147 from aravindiiitb/master
Added Code in Dynamic Programming section for Longest Strictly Increasing Subsequence in O(nlogn) time
2017-10-19 09:37:22 +05:30
Harshil
ec9fdaa918 Merge pull request #160 from kiandru/fastfibonacci
Added fastfibonacci.py
2017-10-14 09:56:08 +05:30
Kilian Rueß
a07baadf04 Added fastfibonacci.py 2017-10-12 21:35:23 +02:00
Sayan Bandyopadhyay
247089decc Update minimum_partition.py
The loop for finding differences had issues of float being iterated. Has been fixed.
2017-10-12 03:28:43 +05:30
KyleScharnhorst
014786e340 Fix: typo in multiple files. 2017-10-07 06:47:50 -07:00
aravindiiitb
e8d0c7e54a Added Code in Dynamic Programming section for Longest Strictly Increasing Subsequence in O(nlogn) time 2017-10-06 12:11:19 +05:30
Chetan Kaushik
fb1b87cefe Merge pull request #107 from mk9440/master
Maximum_subaray_problem
2017-09-10 13:48:59 +05:30