Commit Graph

58 Commits

Author SHA1 Message Date
Nitisha Bharathi
0e619065e7
added Boruvka's MST algorithm (#2026)
* added Boruvka's MST algorithm

* Add files via upload

* fixup! Format Python code with psf/black push

* Updated Boruvka with doctest

* updating DIRECTORY.md

* Update minimum_spanning_tree_boruvka.py

* No blank line in doctest

* <BLANKLINE>

* Avoid mutable default values

https://docs.python-guide.org/writing/gotchas/

* Update minimum_spanning_tree_boruvka.py

* Avoid mutable default values

* fixup! Format Python code with psf/black push

* Update minimum_spanning_tree_boruvka.py

* Update minimum_spanning_tree_boruvka.py

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2020-05-25 15:10:54 +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
Erwin Lejeune
21ed8968c0
Fixes in Bidirectional A* (#2020)
* implement bidirectional astar

* add type hints

* add wikipedia url

* format with black

* changes from review

* fix collision check

* Add testmod()

* # doctest: +NORMALIZE_WHITESPACE

* Codespell: euclidean

* Codespell: coordinates

* Codespell: traversal

* Codespell: remaining

Co-authored-by: John Law <johnlaw.po@gmail.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2020-05-21 21:50:52 +02:00
Erwin Lejeune
dc596d23a9
Graphs : Greedy Best First (#2018)
* implement greedy best first

* implement Greedy Best First Search

* review changes

* add doctests

* >>> gbf.search()  # doctest: +NORMALIZE_WHITESPACE

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-05-20 23:25:48 +02:00
Erwin Lejeune
1f2d607e56
Graphs : Bidirectional A* (#2015)
* implement bidirectional astar

* add type hints

* add wikipedia url

* format with black

* changes from review
2020-05-20 12:20:22 +05:30
siva1098
7469fb6edd
Add graphs/frequent_pattern_graph_miner.py (#1866)
* Add files via upload

* Update graphs/frequent_pattern_graph_miner.py

Co-Authored-By: Christian Clauss <cclauss@me.com>

* Update graphs/frequent_pattern_graph_miner.py

Co-Authored-By: Christian Clauss <cclauss@me.com>

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Update graphs/frequent_pattern_graph_miner.py

Co-Authored-By: Christian Clauss <cclauss@me.com>

* Update graphs/frequent_pattern_graph_miner.py

Co-Authored-By: Christian Clauss <cclauss@me.com>

* Update graphs/frequent_pattern_graph_miner.py

Co-Authored-By: Christian Clauss <cclauss@me.com>

* Update graphs/frequent_pattern_graph_miner.py

Co-Authored-By: Christian Clauss <cclauss@me.com>

* Update graphs/frequent_pattern_graph_miner.py

Co-Authored-By: Christian Clauss <cclauss@me.com>

* Update graphs/frequent_pattern_graph_miner.py

Co-Authored-By: Christian Clauss <cclauss@me.com>

* Update graphs/frequent_pattern_graph_miner.py

Co-Authored-By: Christian Clauss <cclauss@me.com>

* Update graphs/frequent_pattern_graph_miner.py

Co-Authored-By: Christian Clauss <cclauss@me.com>

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Update graphs/frequent_pattern_graph_miner.py

Co-Authored-By: Christian Clauss <cclauss@me.com>

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Update graphs/frequent_pattern_graph_miner.py

Co-Authored-By: Christian Clauss <cclauss@me.com>

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Update frequent_pattern_graph_miner.py

* Whitespace changes

* Format with psf/black

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-05-07 23:30:24 +02:00
Sanders Lin
308505f18f
Add shortest path by BFS (#1870)
* Create breadth_first_search_shortest_path.py

* updating DIRECTORY.md

* Reduce side effect of `shortest_path`

For the sake of future testing and documentation -

* fixup! Format Python code with psf/black push

* Fix typo `separately`

* Change to get() from dictionary

Co-Authored-By: Christian Clauss <cclauss@me.com>

* Move graph to the top

* fixup! Format Python code with psf/black push

* Add doctest for shortest path

* Add doctest for BFS

* fixup! Format Python code with psf/black push

* Add typings for breadth_first_search_shortest_path

* fixup! Format Python code with psf/black push

* Remove assert from doctests

* Add blank line to doctest

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: John Law <johnlaw.po@gmail.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: John Law <johnlaw@linux.com>
2020-05-01 07:24:32 +02:00
Sanders Lin
c92a520956
Update breadth_first_search.py (#1869) 2020-04-19 19:26:52 +05:30
Sanders Lin
7aaf79cc23
Initialize set with source in DFS (#1872)
* Update dfs.py

* Add type hints, rearrange doc-strings and comments

* fixup! Format Python code with psf/black push

* dfs -> depth_first_search

Co-Authored-By: Christian Clauss <cclauss@me.com>

* dfs -> depth_first_search

* Add doctest for DFS

* fixup! Format Python code with psf/black push

* Rename dfs.py to depth_first_search_dictionary.py

* updating DIRECTORY.md

* Rename depth_first_search_dictionary.py to depth_first_search_dfs.py

* updating DIRECTORY.md

* Rename depth_first_search.py to depth_first_search_2.py

* updating DIRECTORY.md

* Rename depth_first_search_dfs.py to depth_first_search.py

* updating DIRECTORY.md

Co-authored-by: John Law <johnlaw.po@gmail.com>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2020-04-17 20:05:29 +02:00
Sanders Lin
d2e8e6215e
Update g_topological_sort.py (#1873) 2020-04-16 12:34:14 +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
onlinejudge95
7b7c1a0135
Fixes unused variable errors in LGTM (#1746)
* Fixes unsed variable errors in LGTM

* Fixes integer check

* Fixes failing tests
2020-02-11 13:59:09 +05:30
Kyle
724b7d2198 Add Prim's algorithm with min heap (#1704) 2020-01-22 02:46:03 +08: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
Kyle
5f57ac975f Add docstr and algorithm to BFS shortest path module (#1637)
* Add docs and type alias to bfs_shortest_path.py

* Add bfs_shortest_path_distance algorithm

* Make requested changes
2019-12-19 10:40:16 +01:00
Christian Clauss
26b0803319
Simplify sudoku.is_completed() using builtin all() (#1608)
* Simplify sudoku.is_completed() using builtin all()

Simplify __sudoku.is_completed()__ using Python builtin function [__all()__](https://docs.python.org/3/library/functions.html#all).

* fixup! Format Python code with psf/black push

* Update sudoku.py

* fixup! Format Python code with psf/black push

* Old style exception -> new style for Python 3

* updating DIRECTORY.md

* Update convex_hull.py

* fixup! Format Python code with psf/black push

* e.args[0] = "msg"

* ValueError: could not convert string to float: 'pi'

* Update convex_hull.py

* fixup! Format Python code with psf/black push
2019-12-08 22:42:17 +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
Bruno Santos
415c9f5e65 Improve prim.py (#1226)
* suiting PEP8

* create auxiliary function

* running example

* updating DIRECTORY.md
2019-12-01 06:13:28 +01:00
John Law
28c02a1f21
Improve bellman_ford.py (#1575)
* Fix out of range error in bellman_ford.py

* Update bellman_ford.py

* fixup! Format Python code with psf/black push

* Enhance the print function

* fixup! Format Python code with psf/black push
2019-11-19 13:52:55 -08:00
JakobZhao
82a11d7f31 Fix bug in bellman_ford.py (#1544) 2019-11-10 17:01:38 +08: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
Daniel Melo
906c985de3 Create dinic.py (#1396)
* Create dinic.py

Dinic's algorithm for maximum flow

* Update dinic.py

Changes made.
2019-10-22 11:37:43 +02:00
Phyllipe Bezerra
455509acee Add Topological Sort (#1302)
* add topological sort

* fix topological sort?

* running black

* renaming file
2019-10-18 08:13:58 +02:00
William Zhang
9eac17a408 psf/black code formatting (#1277) 2019-10-05 10:14:13 +05:00
Hector S
2304e31994 Fixing lgtm issue in basic graphs (#1141)
* Added print function into matrix_multiplication_addition.py and removed blank space in data_structures/binary tree directory

* Removed .vs/ folder per #893

* Rename matrix_multiplication_addition.py to matrix_operation.py

* Fixing lgtm issue in basic_graphs per ##1024

* Fixed lgtm issue per @cclauss recommendation in #1024
2019-08-20 07:02:43 +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
Christian Clauss
3c8e9314b6 Travis CI: Add a flake8 test for unused imports (#1038) 2019-07-25 13:19:00 +05:30
Christian Clauss
0f09530707 dijkstra.py: Use r"strings" to fix two pylint warnings (#1052)
```
=============================== warnings summary ===============================
graphs/dijkstra.py:81
  /home/travis/build/TheAlgorithms/Python/graphs/dijkstra.py:81: DeprecationWarning: invalid escape sequence \ 
    """
graphs/dijkstra.py:97
  /home/travis/build/TheAlgorithms/Python/graphs/dijkstra.py:97: DeprecationWarning: invalid escape sequence \ 
    """
-- Docs: https://docs.pytest.org/en/latest/warnings.html
=================== 126 passed, 7 warnings in 19.35 seconds ====================
```
2019-07-21 00:31:08 +08:00
cclauss
7cdda931fd
Travis CI: Add pytest --doctest-modules graphs (#1018) 2019-07-17 06:07:25 +02:00
Bruno Simas Hadlich
267b5eff40 Added doctest and more explanation about Dijkstra execution. (#1014)
* Added doctest and more explanation about Dijkstra execution.

* tests were not passing with python2 due to missing __init__.py file at number_theory folder

* Removed the dot at the beginning of the imported modules names because 'python3 -m doctest -v data_structures/hashing/*.py' and 'python3 -m doctest -v data_structures/stacks/*.py' were failing not finding hash_table.py and stack.py modules.

* Moved global code to main scope and added doctest for project euler problems 1 to 14.

* Added test case for negative input.

* Changed N variable to do not use end of line scape because in case there is a space after it the script will break making it much more error prone.

* Added problems description and doctests to the ones that were missing. Limited line length to 79 and executed python black over all scripts.

* Changed the way files are loaded to support pytest call.

* Added __init__.py to problems to make them modules and allow pytest execution.

* Added project_euler folder to test units execution

* Changed 'os.path.split(os.path.realpath(__file__))' to 'os.path.dirname()'
2019-07-17 01:09:53 +02:00
Alfonso Rodríguez Pereira
5f991f7740 #315 Renamed all files to snake_case (#993) 2019-07-11 11:16:42 +02:00
PatOnTheBack
2ad5be9919 Modified Docstrings to Fix Errors (#975)
I modified the Docstrings at the beginning of the file to fix D400, W0105, and E402.
2019-07-10 22:00:30 +02:00
zachzhu2016
a212efee5b Corrected wrong Dijkstra priority queue implementation (#909)
* Corrected wrong DFS implementation

* changed list into hash set for dijkstra priority queue implementation.
2019-06-23 23:32:12 +08:00
StephenGemin
a99acae32d Add docstring and comments per Issue #727 (#895)
I've added comments to make understanding this method a little easier for those that are not familiar.  This should close out #727 .

Other changes:
1. added if __name__ == '__main__' rather than the "# MAIN" comment
2. put in return for distances and vertices.  Previously everything was just printed out, but someone may find it useful to have the algorithm return something.
3. Other PEP8 changes
4.  Added example input and expected output as a check to make sure any future changes will give the same output.
2019-06-18 18:28:01 +08:00
zachzhu2016
55e0b0f00a Corrected wrong DFS implementation (#903) 2019-06-17 18:13:36 +08:00
Daniel Xu
ebe227c386 Removed Graphs and move prim.py to graphs (#872)
* Move prim.py from Graphs to graphs

* Removed prim.py from Graphs

* Update prim.py
2019-06-05 09:37:05 +08:00
Guo
f9b8dbf9db Correct the wrong iterative DFS implementation (#867)
* Update DFS.py

* Update DFS.py
2019-06-04 16:34:28 +08:00
Anup Kumar Panwar
71be23999c refactor 2019-05-26 21:56:10 +05:30
Anirudh Ajith
b5667e5ee9 Removed the (incorrectly named) redundant file graph_list.py and renamed graph.py to graph_list.py (#820) 2019-05-21 14:06:05 +08:00
Sarvesh Dubey
f3608acfd5 Created shortest path using bfs (#794)
* Created shortest path using bfs
2019-05-17 11:12:06 +08:00
Erfan Alimohammadi
a65efd42c4 Implement check_bipartite_graph using DFS. (#808) 2019-05-16 19:24:56 +08:00
ImNandha
13c0c166d8 Update graph.py (#809) 2019-05-16 19:23:23 +08:00
Anup Kumar Panwar
e22ea7e380
Update Directed and Undirected (Weighted) Graph.py 2019-05-04 21:53:06 +05:30
Vysor
df04d94543 Some directories had a capital in their name [fixed]. Added a recursive factorial algorithm. (#763)
* Renaming directories
* Adding a recursive factorial algorithm
2019-04-22 22:53:56 +08:00
Reshad Hasan
9a44eb4479 Organize graph algorithms (#719)
* organized graph algorithms

* all graph algorithms in Graphs/ folder

* all graph algorithms are in one folder

* Rename number theory/factorial_python.py to maths/factorial_python.py
2019-02-25 17:35:24 +08:00
Reshad Hasan
af08a67b20 added the dijkstra algorithm (#704) 2019-02-18 23:35:46 +08:00
Rizwan Hasan
c6be53e1c4 Rename Directed and Undirected (Weighted) Graph to Directed and Undirected (Weighted) Graph.py (#686) 2019-01-26 21:09:18 +08:00
Safari
069d2b9cb6
All Python Version 3
Added functions to get all nodes for some algorithms and time calculation for dfs and bfs.
2018-12-16 22:19:40 +03:30
A Safari
b3a15175bd
Added more functionality
Added topological sort, cycle detection and a function to report the nodes participating in cycles in graph(for a use case I myself needed ).
2018-12-14 23:14:35 +03:30