Commit Graph

200 Commits

Author SHA1 Message Date
Christian Clauss
1ad78b2663
Fix invalid escape sequence in binary_search_tree.py (#1920)
* Fix invalid escape sequence in binary_search_tree.py

data_structures/binary_tree/binary_search_tree.py:156
  /home/travis/build/TheAlgorithms/Python/data_structures/binary_tree/binary_search_tree.py:156: DeprecationWarning: invalid escape sequence \

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-05-01 02:17:11 +05:30
Christian Clauss
8bf380ce7d
README.md: sumab() --> sum_ab() for consistancy (#1855)
* README.md: sumab() --> sum_ab() for consistancy  

consistency

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-04-12 17:18:30 +02:00
Sajied Shah Yousuf
c775baf55f
Added new Algorithm to find middle element of Linked List (#1822)
* Added new Algorithm to find middle element of Linked List

* Rename MiddleElementOfLinkedList.py to middle_element_of_linked_list.py

* changed "middle_element_of_linked_list.py" algorithm for taking input

* Update middle_element_of_linked_list.py

* Update middle_element_of_linked_list.py

* Update middle_element_of_linked_list.py

* Update middle_element_of_linked_list.py

* Update middle_element_of_linked_list.py

* Update middle_element_of_linked_list.py

* Update middle_element_of_linked_list.py

* Update middle_element_of_linked_list.py

* Update middle_element_of_linked_list.py

* Whack the trailing whitespace

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-04-12 16:45:07 +02:00
Joan Martin Miralles
a38e143cf8
Binary search tree using recursion (#1839)
* Binary search tree using recursion

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-04-07 18:09:05 +02:00
Prince Gangurde
6043a44ffb
Update basic_binary_tree.py (#1833)
fixed some grammar mistakes
2020-04-07 00:59:32 +02:00
Christian Clauss
f17e9822b0
psf/black changes to next_greater_element.py (#1817)
* psf/black changes to next_greater_element.py

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-03-28 07:24:59 +01:00
Vaibhav Singh
96df906e7a
All suggeted changes within additional time limit tests (#1815)
* With all suggested changes  

possibly covered all the recommended guidelines

* Updated with both slow and faster algorithms

possibally covered all the recomendations

* removed the time comparision part!

* Update data_structures/stacks/next_greater_element.py

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

* Update data_structures/stacks/next_greater_element.py

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

* Update data_structures/stacks/next_greater_element.py

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

* Update data_structures/stacks/next_greater_element.py

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

* Add benchmark using timeit

https://docs.python.org/3/library/timeit.html

The performance delta between these two implementation is quite small...
```
next_greatest_element_slow(): 1.843442126
     next_greatest_element(): 1.828941414
```

* Optimize slow() to create fast() - Three algorithms in the race

Three algorithms in the race

* Use a bigger test array with floats, negatives, zero

* Setup import next_greatest_element_fast

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-03-27 08:16:07 +01:00
KDH
45524dd6d3
Fix rehashing function will not call insert_data function (#1803)
* Fix rehashing function will not call insert_data function

* Fix typo

* Update loop syntax instead of allocating a list

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

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-03-16 11:19:13 +01:00
KDH
cb5f8c6e4e
Fix typo (#1797)
colision => collision
2020-03-13 13:46:52 +01:00
Christian Clauss
a9f73e318c
Added SkipList (#1781)
* Added SkipList

* Add missing type hints and doctests

* Add missing doctest

* Tighten up doctest

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-03-05 17:57:43 +01: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
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
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
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
lanzhiwang
fc4c0f5bfd implement max heap and more pythonic (#1685)
* implement max heap and more pythonic

* add doctests for heap
2020-01-14 12:16:11 +01:00
Logan Lieou
d09a805804 Typo? (#1653)
* Typo?

newNod -> newNode

* newNode -> new_node

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-01-14 10:21:02 +01:00
lanzhiwang
56e7ae01d2 enhance swapping code in link (#1660)
* enhance swapping code in link

* heapify do not recursive

* fix

* fix identifier and add test

* typing.Any and LinkedList instead of Linkedlist

* typing.Any and LinkedList instead of Linkedlist
2020-01-14 14:32:15 +05:30
Leon Morten Richter
4607cd48b6 Add a program to evaluate a string in prefix notation (Polish Notation) (#1675)
* Create infix_evaluation.py

* fix doctests

* Rename infix_evaluation.py to prefix_evaluation.py

* Add prefix_evaluation.py to directory
2020-01-12 15:00:40 +05:30
Christian Clauss
e849578e59 Update and rename lca.py to lowest_common_ancestor.py (#1664)
* Update and rename lca.py to lowest_common_ancestor.py

* fixup! Format Python code with psf/black push
2020-01-08 21:15:41 +08:00
Christian Clauss
1f2b1a88ab Typos in comments in hill_climbing.py (#1667)
* Typos in comments in hill_climbing.py

* fixup! Format Python code with psf/black push
2020-01-08 21:06:53 +08:00
MadhavCode
46df735cf4 New Code!!(Finding the N Possible Binary Search Tree and Binary Tree from Given N node Number) (#1663)
* Code Upload

* Code Upload

* Delete n_possible_bst

* Find the N Possible Binary Tree and Binary Tree from given Nth Number of Node.

* Update in Test

* Update and rename n_possible_bst.py to number_of_possible_binary_trees.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-01-07 10:17:35 +01:00
Himanshu Bhatnagar
b212a59754 Create deque_doubly.py (#1652)
* Create deque_doubly.py

Implementing Deque ADT using Doubly Linked List....

* Update deque_doubly.py

* Update deque_doubly.py

Adding doctest

* Update doctest of deque_doubly.py

* Update deque_doubly.py

* linked_list.

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-01-05 10:51:03 +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
Dhakad9
aa18600e22 Stack using double linked list (#1413)
* Stack using double linked list

* Test with doctests

* Update stack_using_dll.py

* Update stack_using_dll.py

* Update stack_using_dll.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2019-12-21 02:46:49 +01:00
Hocnonsense
81ae5adcc8 Update binary_search_tree.py (#1339)
* Update binary_search_tree.py

remove some bugs

* Update binary_search_tree.py

* Update binary_search_tree.py

* Update binary_search_tree.py

* Update binary_search_tree.py

* Update binary_search_tree.py

* Update binary_search_tree.py

* testlist = (8, 3, 6, 1, 10, 14, 13, 4, 7)

* Update .travis.yml

Co-authored-by: Christian Clauss <cclauss@me.com>
2019-12-21 01:44:31 +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
Níkolas Vargas
938dd0bbb5 improved prime numbers implementation (#1606)
* improved prime numbers implementation

* fixup! Format Python code with psf/black push

* fix type hint

* fixup! Format Python code with psf/black push

* fix doctests

* updating DIRECTORY.md

* added prime tests with negative numbers

* using for instead filter

* updating DIRECTORY.md

* Remove unused typing.List

* Remove tab indentation

* print("Sorted order is:", " ".join(a))
2019-12-07 06:39:08 +01:00
Saurabh Goyal
5d20dbfb98 add a generic heap (#906)
* add a generic heap

* Delete __init__.py

* Rename data_structures/Heap/heap_generic.py to data_structures/heap/heap_generic.py

* Add doctests

* Fix doctests

* Fix doctests again
2019-11-30 06:17:13 +01:00
Vikas Kumar
0d3c9d586c Update singly_linked_list.py (#1593)
* Update singly_linked_list.py

printing current.data rather than node address in __repr__ for a more readable print statement

* eval(repr(c)) == c

The output of `__repr__()` _should look like a valid Python expression that could be used to recreate an object with the same value_.

https://docs.python.org/3.4/reference/datamodel.html#object.__repr__

* += --> +
2019-11-26 06:45:28 +01:00
Christian Clauss
ec7bc7c7cd Tabs --> spaces in quine_mc_cluskey.py (#1426)
* Tabs --> spaces in quine_mc_cluskey.py

* fixup! Format Python code with psf/black push
2019-11-21 22:21:40 +08:00
onlinejudge95
c57c4ca1a1 Adds operations for circular linked list (#1584)
* Adds, append, len, print operations for circular linked list

* Adds, prepend support

* Adds, delete from front of the list

* Adds, delete_rear support

* Adds, method documentations

* Adds, type checking and doctests

* Updates doctest for delete ops

* Addressing requested changes

* Removes unused import

* Fixes failing doctests

* Minor modifications...
2019-11-19 10:53:44 +01:00
Himanshu Bhatnagar
0832e1ec58 Adding circular_queue.py (#1574)
* Create circular_queue.py

Circular Queue implementation using python list with fixed range.

* Update circular_queue.py

* Update circular_queue.py

* Update circular_queue.py

* Update circular_queue.py

* Update circular_queue.py

* doctest: Catch "Exception: UNDERFLOW"

* Deal with the fluent interface for cq.enqueue()

* Test the fluent interface
2019-11-17 19:59:50 +01: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
Hanif Ali
4c37eb7d07 Improved on Singly Linked List Programs (#1558)
* Improved Singly Linked List
Added String Representations of Nodes and Linked Lists
Added support for indexing and changing of Node data using indices.

* Added a few comments to Linked Lists

* Reformatted to conform to PEP8

* Added from_sequence.py
Convert a Python List to Linked List comprising of Nodes and return head.

* Added print_reverse.py
Recursive program to print the elements of a Linked List in reverse.

* Change 'is not None' for more Pythonicness
2019-11-10 09:47:04 +01:00
Jonathan Alberth Quispe Fuentes
7bc0462e79 Non-recursive Segment Tree implementation (#1543)
* Non-recursive Segment Tree implementation

* Added type hints and explanations links
2019-11-01 04:00:46 +01:00
himanshujain171
53ff735701 Factors of a number (#1493)
* Factors of a number

* Update factors.py

* Fix mypy issue in basic_maths.py

* Fix mypy error in perceptron.py

* def primes(max: int) -> List[int]:

* Update binomial_heap.py

* Add a space

* Remove a space

* Add a space
2019-10-29 23:54:30 +01:00
Samarth Sehgal
a2a3ca674f Update treap.py (#1455) 2019-10-25 17:56:27 +02: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
Manu M Bhat
cd10c944d1 Issue #1397 (#1403) 2019-10-19 20:14:37 +02:00
Jai Kumar Dewani
5ef5f67a51 Added more details about the problem statement (#1367)
* Update DIRECTORY

* Updated DIRECTORY

* Fixed bug in directory build and re-build the directory.md

* fixed url issue

* fixed indentation in Directory.md

* Add problem-18 of project-euler

* Delete sol1.py

* Delete files

* Added more details to question

* Added doctest in printNGE()

* Made changes to fix Travis CI build

* Remove the trailing whitespace
2019-10-18 21:14:01 +02:00
Hocnonsense
179284a41b Update treap.py (#1358)
* Update treap.py

check merge()

* Update treap.py

random() is used. its difficult to write doctests
l->left
r->right
key->value
add __repr__ and __str__ in preorder
2019-10-18 09:39:37 +02:00
Mariusz Skoneczko
7376addcd5 Implement Linked Queue and Linked Stack data structures (#1324)
* Add LinkedQueue

* Add LinkedStack
2019-10-18 08:38:31 +02:00
Nishant-Ingle
06d736199b Added comment (#1294) 2019-10-07 23:29:14 +05:00
William Zhang
9eac17a408 psf/black code formatting (#1277) 2019-10-05 10:14:13 +05:00
yijoonsu
189b350312 Deque (#1200)
* deque add pop

* deque add remove
2019-09-30 16:27:41 +02:00
Raj
6ac7b1387f Min head with decrease key functionality (#1202)
* Min head with decrease key functionality

* doctest added

* __str__ changed as per Python convention

* edits in doctest

* get_value by key added

* __getitem__ added
2019-09-26 00:03:31 +02:00
luoheng
01601e6382 Add disjoint set (#1194)
* Add disjoint set

* disjoint set: add doctest, make code more Pythonic

* disjoint set: replace x.p with x.parent

* disjoint set: add test and refercence
2019-09-23 05:08:20 +02:00
Denis Trofimov
04962c0d17 Fix lgtm error display #1024 (#1190)
* fix: Syntax Error lgtm display in matrix/matrix_operation.py.

* Testing for None should use the 'is' operator.

* fix: Too many arguments for string format.

* fix: supress lgtm alert as false positive.

* style: Unnecessary 'pass' statement.

* Revert "fix: Syntax Error lgtm display in matrix/matrix_operation.py."

This reverts commit 4c629b4ce1.
2019-09-21 16:23:34 +02:00