Commit Graph

99 Commits

Author SHA1 Message Date
Hasanul Islam
95862303a6
Fix mypy at prims_algo_2 (#4527) 2021-07-05 08:23:18 +02:00
Hasanul Islam
86baec0bc9
Fix mypy errors at bfs_zero_one_shortest_path (#4521) 2021-07-02 13:52:26 +02:00
Hasanul Islam
62d4418851
Fix mypy error and add more doctest on bfs_shortest_path (#4512) 2021-06-29 19:44:35 +08:00
Hasanul Islam
3ea5a13334
Add doctest and fix mypy type annotation in bellman ford (#4506) 2021-06-24 08:50:23 +02:00
Hasanul Islam
977511b3a3
Add/fix mypy type annotations at BFS, DFS in graphs (#4488) 2021-06-10 22:36:41 +05:30
algobytewise
ce99859ad5
Move files to various folders (#4286)
* Move files to cellular_automata

* Rename other/davis–putnam–logemann–loveland.py to backtracking/davis–putnam–logemann–loveland.py

* Rename other/markov_chain.py to graphs/markov_chain.py

* undid rename: need to fix mypy first
2021-03-22 10:54:04 +01:00
Nwachukwu Chidiebere Godwin
03d34350f6
Graph list patch (#4113)
* new implementation for adjacency list graph

* add example code for undirected graph

* reduce length to 88 columns max to fix build errors7

* fix pre commit issues

* replace print_list method with __str__

* return object in add_edge method to enable fluent syntax

* improve class docstring and include doctests

* add end of file line

* fix pre-commit issues

* remove __str__ method

* trigger build

* Update graph_list.py

* Update graph_list.py

Co-authored-by: gnc <chidieberen1999@gmail.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2021-01-12 14:41:48 +01:00
Lewis Tian
c39be1d8b8
update graphs/breadth_first_search.py (#3908)
* update graphs/breadth_first_search.py

- update naming style to snake_case
- add type hints

* add doctests
2020-12-09 17:21:46 +08:00
Akash G Krishnan
fa364dfd27
Changed how the Visited nodes are tracked (#3811)
Updated the code to track visited Nodes with Set data structure instead of Lists to bring down the lookup time in visited  from O(N) to O(1)
as doing O(N) lookup each time in the visited List will become significantly slow when the graph grows
2020-11-21 12:28:52 +05:30
Lewis Tian
83a24cb06d
Update graphs/graph_list.py (#3813)
- update naming style to snake_case
- add type hints
2020-11-08 20:34:01 +05:30
Lewis Tian
4fa8c9d4b4
Update graphs/depth_first_search_2.py (#3799)
- update naming style to snake_case
- add type hints
2020-10-29 08:35:31 +08:00
Phil Bazun
5be77f33f7
Add 0-1-bfs. (#3285)
* Add 0-1-bfs.

* fixup! Add 0-1-bfs.

* fixup! Add 0-1-bfs.

* Check edge weights.

* Check edge vertecies.
2020-10-24 23:07:04 +02: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
Christian Clauss
5b024f4dd5
BROKEN BUILD: Fix a failing precommit test (#3344)
* Fix a failing precommit test

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-10-16 00:33:25 +02:00
Meysam
cc050dbf5b
test/graphs/prim: writing a test case to verify the correctness of the algorithm (#2454) 2020-10-15 21:10:35 +02:00
Meysam
83b825027e
Graphs/kruskal: adding doctest & type hints (#3101)
* graphs/kruskal: add doctest & type hints

this is a child of a previous PR #2443

its ancestor is #2128

* updating DIRECTORY.md

* graphs/kruskal: fix max-line-length violation

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-10-15 21:08:52 +02:00
Tapajyoti Bose
02d3ab81bd
feat: added prim's algorithm v2 (#2742)
* feat: added prim's algorithm v2

* updating DIRECTORY.md

* chore: small tweaks

* fixup! Format Python code with psf/black push

* chore: added algorithm descriptor

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-10-10 12:18:52 +05:30
Meysam
c2a5033f9e
graphs/kruskal: add a test case to verify the correctness, fix styles (#2443)
* test/graphs/kruskal: adding a test case to verify the correctness of the algorithm

Fixes #2128

* grahps/kruskal: running psf/black

* graphs/kruskal: read edges in a friendlier fashion

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

* Update minimum_spanning_tree_kruskal.py

* fixup! Format Python code with psf/black push

* Update test_min_spanning_tree_kruskal.py

* updating DIRECTORY.md

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: John Law <johnlaw.po@gmail.com>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-10-08 20:21:48 +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
d6bff5c133
Renamed files and fixed Doctest (#2421)
* * Renamed files
* Fiexed doctest

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-09-13 13:27:20 +02:00
Hasenn
20e98fcded
Fix some warnings from LGTM (#2420)
* fix assignment of a variable to itself

* Fix unnecessary 'else' clause in loop

* formatting and redundant reasignment fix

* mark unreachable code with a TODO comment

* fix variable defined multiple times

* fix static method without static decorator

* revert unintended autoformatting

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

* revert autoformatting issue

* applied black autoformatting

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-09-13 10:11:27 +02:00
Marcos Cannabrava
a191f89fe2
Fix Non Recursive Depth First Search (#2207)
* Fix Non Recursive Depth First Search

* Unindent docstring

* Reindent docstring by 1 space

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

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-09-11 16:23:26 +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
Tapajyoti Bose
aa46639cbc
Added Kruskal's Algorithm (more organized than the one present) (#2218)
* Added Kruskal's Algorithm

* Added Type Hints

* fixup! Format Python code with psf/black push

* Added Type Hints V2

* Implemented suggestions + uniform naming convention

* removed redundant variable (self.nodes)

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-08-12 12:16:17 +02:00
Christian Clauss
1fb1fdd130
requirements.txt: Unpin numpy (#2287)
* requirements.txt: Unpin numpy

* fixup! Format Python code with psf/black push

* Less clutter

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-08-06 17:50:23 +02:00
Arin Khare
c6c9f4707b
Karger's Algorithm (#2237)
* Add implementation of Karger's Algorithm

* Remove print statement from karger's algorithm function

* Fix style issues in graphs/karger.py

* Change for loops to set comprehensions where appropriate in graphs/karger.py
2020-08-01 09:30:34 +05:30
KARTHIKEYAN ANBARASU
e292ddb5ec
Update basic_graphs.py (#1990)
* Update basic_graphs.py

missing return statement line no:223.

* Update basic_graphs.py

Co-authored-by: vinayak <itssvinayak@gmail.com>
2020-07-13 09:17:13 +05:30
Marcos Cannabrava
728c0df355
Fix typo: Adjancent -> Adjacent (#2184) 2020-07-06 22:00:07 -05:00
Christian Clauss
2c75a7b3dd
Numerous fixes to directed_and_undirected_(weighted)_graph.py (#2182)
* Numerous fixes to directed_and_undirected_(weighted)_graph.py

* dict.keys() is almost never need in modern Python
2020-07-06 19:31:04 +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
Akash Shroff
25d9d819a2
Gale Shapley Algorithm (#2100)
* Gale Shapley Algorithm

Implementation of a Nobel prize-winning algorithm that determines a stable matching in a bipartite graph.

* Update graphs/gale_shapley_bigraph.py

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

* Fixed some flake8 issues.

* Updated it to donors and recipients

* description changes

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

* description changes

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

* description changes

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

* Edited the line lengths

* Update gale_shapley_bigraph.py

* Update gale_shapley_bigraph.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-07-05 11:21:32 +02:00
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
wuyudi
d2fa91b18e
Add url and typing hint for BFS (#2156)
* Add typing for bfs

* Add url for BFS

* rename the function

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

* Update graphs/bfs.py

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

* Change the return value type of bfs

* change the function name.

change all instances of bfs() to breadth_first_search().

* change the function name in annotate

* Add one more blank line.

* Delete one blank line.

* Delete one blank line.

I've read the https://www.flake8rules.com/rules/W391.html, and still don't know how to do it. I've tried using 0 ,1,2 blank lines...

* Update graphs/bfs.py

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

* Update graphs/bfs.py

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

* Rename bfs.py to breadth_first_search_2.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-06-25 17:54:41 +02:00
Nika Losaberidze
fb3a228d26
Strongly connected components (#2114)
* Implement strongly connected components for graph algorithms

* fixup! Format Python code with psf/black push

* Delete trailing whitespace

* updating DIRECTORY.md

* Add doctests and typehints

* Remove unnecessary comments, change variable names

* fixup! Format Python code with psf/black push

* Change undefined variable's name

* Apply suggestions from code review

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-06-17 18:16:54 +02:00
Nika Losaberidze
2bbdc3bfe7
Implement connected components algorithm for graphs (#2113)
* Implement connected components algorithm for graphs

* fixup! Format Python code with psf/black push

* Add parameters and return values annotations with Python type hints

* updating DIRECTORY.md

* Add doctests and typehints

* Remove unnecessary comments, change variable names

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-06-17 18:15:24 +02:00
Christian Clauss
f97af65579
Blacken our code (#2125)
* Blacken

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-06-17 06:59:38 +08:00
beqakd
924ef9b7d8
implementation of entropy algorithm. (#2110)
* implementation of entropy algorithm.

* add tests, fix requested changes

* open_file() --> analyze_text()

* Create bidirectional_breadth_first_search.py

* # type: ignore

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-06-16 21:36:57 +02:00
Erwin Lejeune
a5c246793c
Graphs : Bidirectional Breadth-First Search (#2057)
* implement bidirectional breadth first

* remove useless import

* remove trailing whitespaces
2020-06-16 17:10:22 +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
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