Commit Graph

143 Commits

Author SHA1 Message Date
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
Mayank Kumar Jha
aae156252f Update longest common subsequence.py 2017-08-30 23:03:48 +05:30
Mayank Kumar Jha
0e857d8905 Add files via upload 2017-08-29 19:45:15 +05:30
mandy8055
0d01a4a0aa Added one of the most important machine learning algorithm
The k-means clustering is done by using tensorflow which is the vital and growing machine learning library of google.
2017-07-30 00:42:32 +05:30
Mehdi ALAOUI
ce8b025320 Adding spaces between operators 2017-04-12 14:45:56 +01:00
Mehdi ALAOUI
9a756d1940 Fixing some terms number issue, and improving result for first terms (0 and 1) 2017-04-11 23:10:52 +01:00
Mehdi ALAOUI
08cbd113a4 Code optimized and complexity decreased 2017-04-10 13:49:01 +01:00
Mehdi ALAOUI
e01cf425bd Comments reviewed 2017-04-07 03:27:15 +01:00
Mehdi ALAOUI
628f184af5 The program returns now the longest increasing subsequence instead of returning only the length. Code optimized and well commented 2017-04-07 03:19:02 +01:00
umesh
a43d0f312a corrected title 2017-01-10 00:14:48 +05:30
umesh
655aecc338 corrected problem title 2017-01-10 00:11:50 +05:30
dhruvsaini
436edf3a88 Create longest_increasing_subsequence.py
The Longest Increasing Subsequence (LIS) problem is to find the length of the longest subsequence of a given sequence such that all elements of the subsequence are sorted in increasing order. For example, the length of LIS for {10, 22, 9, 33, 21, 50, 41, 60, 80} is 6
2017-01-03 16:54:38 +05:30
dhruvsaini
5a3059784f Create knapsack.py
Given weights and values of n items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack.
2017-01-03 16:50:13 +05:30
dhruvsaini
688a9ab3bc Create minimum_partition.py
Partition a set into two subsets such that the difference of subset sums is minimum
2017-01-03 16:42:31 +05:30
dhruvsaini
8e29c832a7 Create longest common subsequence.py
LCS Problem Statement: Given two sequences, find the length of longest subsequence present in both of them.
A subsequence is a sequence that appears in the same relative order, but not necessarily continious.
Example:"abc", "abg" are subsequences of "abcdefgh".
2017-01-02 20:51:37 +05:30
Yvonne
ac5d2354ba add sum of the longest sub array 2016-11-29 13:18:47 +08:00
Turfa Auliarachman
93e5e1b8d3 Add Edit Distance DP Algorithm 2016-10-12 21:48:37 +07:00
Akshay Sharma
2dcb85d581 PEP style 2016-09-26 16:09:59 +05:30
Akshay Sharma
a3c5167fad pep style and fixed exception on input other and integer type 2016-09-26 16:08:40 +05:30
Akshay Sharma
7c90322815 dp intro ro fr fibonacci.py 2016-09-26 15:58:43 +05:30
Akshay Sharma
edf9dd2156 dynamic_programming, fibonacci sequence. 2016-09-26 15:56:23 +05:30