Commit Graph

229 Commits

Author SHA1 Message Date
NEERAJ ADITYANANTH POLAMPALLI
3b1c4f72ce
changed a typo (#2396) 2020-09-05 13:09:18 +02:00
kanthuc
472f63eaa5
Adding type hints to RedBlackTree (#2371)
* redblacktree type hints

* fixed type hints to pass flake8
2020-08-30 21:22:36 +02:00
Aanuoluwapo Babajide
1f5134b368
Create alternate_disjoint_set.py (#2302)
* Create alternate_disjoint_set.py

This code implements a disjoint set using Lists 
with added heuristics for efficiency
Union by Rank Heuristic and Path Compression

* Update alternate_disjoint_set.py

Added typehints, doctests and some suggested variable name change

* Update alternate_disjoint_set.py

* Formatted with Black

* More formatting

* Formatting on line 28

* Error in Doctest

* Doctest Update in alternate disjoint set

* Fixed build error

* Fixed doctest
2020-08-28 18:25:02 +02:00
kanthuc
f8c57130f2
lazy_segment_tree.py-style-fixes (#2347)
* fixed variable naming and unnecessary type hints

* print(segt)

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-08-24 09:52:02 +02:00
SiddhantBobde
0bf1f22d37
Added function for finding K-th smallest element in BST (#2318)
* fixes: #2172

* fixes: #2172

* Added docstrings and type of parameters

* fixed error

* Added type hints

* made changes

* removed capital letters from function name

* Added type hints

* fixed bulid error

* modified comments

* fixed build error
2020-08-21 12:25:50 +05:30
Du Yuanchao
0591968947
Optimization and fix bug (#2342)
* * optimization aliquot_sum
* fix bug in average_median

* fixup! Format Python code with psf/black push

* Update maths/average_median.py

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-08-21 14:39:03 +08:00
kanthuc
2eaacee7b4
lowest_common_ancestor.py static type checking (#2329)
* adding static type checking to basic_binary_tree.py

* Add static type checking to functions with None return type

* Applying code review comments

* Added missing import statement

* fix spaciing

* "cleaned up depth_of_tree"

* Add doctests and then streamline display() and is_full_binary_tree()

* added static typing to lazy_segment_tree.py

* added missing import statement

* modified variable names for left and right elements

* added static typing to lowest_common_ancestor.py

* fixed formatting

* modified files to meet style guidelines, edited docstrings and added some doctests

* added and fixed doctests in lazy_segment_tree.py

* fixed errors in doctests

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-08-21 06:54:34 +02:00
Alex Joslin
d3199da000
Created Dijkstra's Two Stack Algorithm (#2321)
* created dijkstra's two stack algorithm

* Made changes to dijkstras two stack algorithm for documentation and
testing purposes.

* Made changes to dijkstras two stack algorithm for documentation and
testing purposes.

* Fixed Grammar Mistake

* Added Explanation Reference

* Imported stack instead of using my own
Changed a few minor things.

* Imported stack instead of using my own
Changed a few minor things.

* Update data_structures/stacks/dijkstras_two_stack_algorithm.py

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

* Update dijkstras_two_stack_algorithm.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-08-20 17:49:43 +02:00
Du Yuanchao
d687030d9e
fix number_of_digits bug (#2301)
* fix bug

* test larger negative

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-08-12 18:32:35 +02:00
kanthuc
d25a926c02
adding static type checking to basic_binary_tree.py (#2293)
* adding static type checking to basic_binary_tree.py

* Add static type checking to functions with None return type

* Applying code review comments

* Added missing import statement

* fix spaciing

* "cleaned up depth_of_tree"

* Add doctests and then streamline display() and is_full_binary_tree()

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-08-11 23:38:38 +02:00
TheSuperNoob
b2e8672f02
Fix doubly linked list algorithm (#2062)
* Fix doubly linked list algorithm

* Fix bug with insert_at_tail method

Create __str__() method for Node class and LinkedList class

* Simplify __str__() of LinkedList

Returns empty string if there are no elements in the list

* Fix description
2020-08-02 23:55:18 +08:00
Sumuk Shashidhar
e2ee52d773
removed redundant data_structures folder (#2256) 2020-07-31 20:36:02 +02:00
Palash Sharma
ee282d3687
Update min_heap.py (#2245)
Changed min head to min heap in the first line.
2020-07-28 07:55:35 +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
8ab84fd794
Only one carriage return (#2155)
* updating DIRECTORY.md

* touch

* fixup! Format Python code with psf/black push

* Update word_frequency_functions.py

* updating DIRECTORY.md

* Update word_frequency_functions.py

* Update lfu_cache.py

* Update sol1.py

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-06-25 19:15:30 +02:00
Markgolzh
c7ca9cf0df
Update avl_tree.py (#2145)
* Update avl_tree.py

it's true definition of AVL tree,change  left and right rotation,and add avl_tree doctest

* Update avl_tree.py

* Update data_structures/binary_tree/avl_tree.py

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

* Update data_structures/binary_tree/avl_tree.py

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

* Update data_structures/binary_tree/avl_tree.py

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

* Update data_structures/binary_tree/avl_tree.py

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

* Update data_structures/binary_tree/avl_tree.py

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

* Update data_structures/binary_tree/avl_tree.py

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

* Update data_structures/binary_tree/avl_tree.py

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

* Update data_structures/binary_tree/avl_tree.py

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

* Update data_structures/binary_tree/avl_tree.py

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

* Update data_structures/binary_tree/avl_tree.py

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

* Update data_structures/binary_tree/avl_tree.py

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

* Update avl_tree.py

update some function name and update doctest

* Update avl_tree.py

change some code format to fit flake8 review

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-06-25 09:55:13 +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
Lakshmikanth2001
321b1425e3
data_structures/linked_list: Add __len__() function and tests (#2047)
* Update __init__.py

please add a function to get length of linked list

* Update __init__.py

* Update doubly_linked_list.py

all size function lo doubly linked list class

* prime number _better method

* comments

* Updated init.py 2

made it more pythonic

* updated length function

* commnet in linked_list construtor

* Update data_structures/linked_list/__init__.py

accepecting changes

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

* Update data_structures/linked_list/__init__.py

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

* Update __init__.py

* Revert changes to doubly_linked_list.py

* Revert changes to prime_check.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-05-31 11:37:45 +02:00
Christian Clauss
1e8fe8efcf
circular_linked_list: Add more len() tests (#2051)
* circular_linked_list: Add more len() tests

* fixup! Format Python code with psf/black push

* prepend()

* updating DIRECTORY.md

* Fix decrementation of self.length

* Add empty list tests

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-05-31 13:06:57 +05:30
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
Christian Clauss
0e6e5056b3
singly_linked_list.py: psf/black (#2008)
* singly_linked_list.py: psf/black

* updating DIRECTORY.md

* Update singly_linked_list.py

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-05-19 13:54:25 +02:00
Christian Clauss
1c62bd10c1
Precision must be a nonnegative integer (#2013)
* Precision must be a nonnegative integer

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-05-19 15:46:20 +05:30
Akash
f9e0dd94d6
added __len__ function (#1812)
* added __len__ function

Added a function to count number of nodes in linked list

* Updated __len__ method

used snake_case instead of camel case

* Add tests to __len__()

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-05-18 18:10:55 +02:00
halilylm
1151d8b157
Add type hints to max_heap.py (#1960)
* Max heap implementation

* Update max_heap.py

* Update max_heap.py

* Update max_heap.py

* __len__ method added

* Update max_heap.py

Co-authored-by: halilpython <65048618+halilpython@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2020-05-11 12:23:39 +02:00
Vipul Rai
3d4ccc383a
change method name from front to get_front (#1943)
Co-authored-by: “Vipul <“vipulrai8891@gmail.com”>
2020-05-06 11:19:44 +05:30
Christian Clauss
d1b25760bc
Fix psf/black issues than fail the build (#1935)
* Fix psf/black issues than fail the build

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-05-03 23:58:44 +02:00
Akash
b6fcee3114
Check if a item exist in stack or not (#1931)
* Check if a item exist in stack or not

* implemented __contains__ method in stack

* made changes in __contains__
2020-05-03 16:15:31 +02:00
lanzhiwang
853741e518
enhanced segment tree implementation and more pythonic (#1715)
* enhanced segment tree implementation and more pythonic

enhanced segment tree implementation and more pythonic

* add doctests for segment tree

* add type annotations

* unified processing sum min max segment tre

* delete source encoding in segment tree

* use a generator function instead of returning

* add doctests for methods

* add doctests for methods

* add doctests

* fix doctest

* fix doctest

* fix doctest

* fix function parameter and fix determine conditions
2020-05-02 21:44:29 +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
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