Skip to content

Commit bec3eb7

Browse files
author
Michele De Vita
committed
Merge remote-tracking branch 'upstream/master'
Moved implentation of kruskal into WeightedGraph class into data_structures/graph.py and refactor relative tests. Changed some implementation details into Graph class to simplify the code into add_edge method
2 parents d4bd356 + 8f14fbb commit bec3eb7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1967
-242
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ docs/_build/
5555

5656
# PyBuilder
5757
target/
58+
.idea/

README.rst

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ Installation
3131
pip3 install pygorithm
3232

3333
- | It's that easy. If you are using Python 2.7 use pip instead. Depending on your
34-
| permissions, you might need to ``sudo`` before installing
34+
| permissions, you might need to use ``pip install --user pygorithm`` to install.
35+
36+
* Or you can download the source code from `here <https://github.com/OmkarPathak/pygorithm>`_, and then just install the package using
37+
38+
::
39+
40+
python setup.py install
3541

3642

3743
Quick Start Guide
@@ -63,3 +69,30 @@ Quick Start Guide
6369
from pygorithm.sorting import bubble_sort
6470
time_complexity = bubble_sort.time_complexities()
6571
print(time_complexity)
72+
73+
* To see all the available functions in a module. For example, if you want to see what all sorts are available in the sorting module, then just do
74+
75+
.. code:: python
76+
77+
>>> from pygorithm.sorting import modules
78+
>>> modules()
79+
['bubble_sort', 'bucket_sort', 'counting_sort', 'heap_sort', 'insertion_sort', 'merge_sort', 'quick_sort', 'selection_sort', 'shell_sort']
80+
81+
Tests
82+
~~~~~
83+
84+
* Just type in the following command to run the tests
85+
::
86+
87+
python3 -m unittest
88+
89+
* This will run all the tests defined in the files of the ``tests/`` directory
90+
91+
92+
Donation
93+
~~~~~~~~
94+
95+
If you have found my softwares to be of any use to you, do consider helping me pay my internet bills. This would encourage me to create many such softwares :)
96+
97+
- `PayPal <https://paypal.me/omkarpathak27>`_
98+
- `₹ (INR) <https://www.instamojo.com/@omkarpathak/>`_

TODO.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# TODO
2+
3+
### Tree
4+
5+
- [x] Binary Tree
6+
- [x] Binary Search Tree
7+
- [ ] Inorder to Preorder
8+
- [ ] Count Leaf Nodes
9+
10+
### Graph
11+
12+
- [x] Graph implementation
13+
- [x] Detect cycle in Graph
14+
- [x] Topological Sort
15+
- [ ] Prim's Algorithm
16+
- [ ] Kruskal's Algorithm
17+
18+
### Dynamic Programming
19+
20+
- [ ] Fibonacci
21+
- [ ] Longest Increasing Subsequence
22+
23+
### Heap
24+
25+
- [x] Heap implementation
26+
- [x] Heap Sort

docs/Data_Structure.rst

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
===============
2+
Data Structures
3+
===============
4+
5+
Implementing Data Structures purely in Python.
6+
7+
Quick Start Guide
8+
-----------------
9+
10+
.. code-block:: python
11+
12+
# import the required data structure
13+
from pygorithm.data_structures import stack
14+
15+
# create a stack with default stack size 10
16+
myStack = stack.Stack()
17+
myStack.push(2)
18+
19+
# print the contents of stack
20+
print(myStack)
21+
22+
Features
23+
--------
24+
25+
* Data Structures implementations available:
26+
- **Stack**
27+
- Stack (data_structures.stack.Stack)
28+
- Infix to Postfix conversion (data_structures.stack.InfixToPostfix)
29+
- **Queue**
30+
- Queue (data_structures.queue.Queue)
31+
- Deque (data_structures.queue.Deque)
32+
- **Linked List**
33+
- Singly Linked List (data_structures.linked_list.SinglyLinkedList)
34+
- Doubly Linked List (data_structures.linked_list.DoublyLinkedList)
35+
- **Tree**
36+
- Binary Tree (data_structures.tree.BinaryTree)
37+
- Binary Seach Tree (data_structures.tree.BinarySearchTree)
38+
- **Graph**
39+
- Graph (data_structures.graph.Graph)
40+
- Topological Sort (data_structures.graph.TopologicalSort)
41+
- Check cycle in Directed Graph (data_structures.graph.CheckCycleDirectedGraph)
42+
- Check cycle in Undirected Graph (data_structures.graph.CheckCycleUndirectedGraph)
43+
- **Heap**
44+
- Heap (data_structures.heap.Heap)
45+
46+
* Get the code used for any of the implementation
47+
48+
.. code:: python
49+
50+
from pygorithm.data_structures.stack import Stack
51+
52+
myStack = Stack()
53+
print(myStack.get_code())
54+
55+
* To see all the available functions in a module there is a `modules()` function available. For example,
56+
57+
.. code:: python
58+
59+
>>> from pygorithm.data_structures import modules
60+
>>> modules()
61+
['graph', 'heap', 'linked_list', 'queue', 'stack', 'tree']
62+
63+
Stack
64+
-----
65+
66+
.. automodule:: pygorithm.data_structures.stack
67+
68+
Stack
69+
-----
70+
.. autoclass:: Stack
71+
:members:
72+
73+
.. automodule:: pygorithm.data_structures.stack
74+
75+
Stack
76+
-----
77+
.. autoclass:: InfixToPostfix
78+
:members:

docs/Fibonacci.rst

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
=========
2+
Fibonacci
3+
=========
4+
5+
Learning fibonacci implementations in few ways!
6+
7+
Quick Start Guide
8+
-----------------
9+
10+
.. code-block:: python
11+
12+
from pygorithm.fibonacci import recursion as fib_recursion
13+
14+
sequence = fib_recursion.get_sequence(10)
15+
print(sequence) # [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
16+
17+
Features
18+
--------
19+
20+
* Fibonacci implementations available:
21+
- Recursion
22+
- Cache (which saves some recursions to avoid computation of same series again and again)
23+
24+
* Get the code used for any of the implementation
25+
26+
.. code:: python
27+
28+
from pygorithm.fibonacci import recursion as fib_recursion
29+
30+
code = fib_recursion.get_code()
31+
print(code)
32+
33+
* To see all the available functions in a module there is a `modules()` function available. For example,
34+
35+
.. code:: python
36+
37+
>>> from pygorithm.fibonacci import modules
38+
>>> modules()
39+
['cache', 'recursion']
40+
41+
Implementations API
42+
-------------------
43+
44+
* Functions and their uses
45+
46+
.. function:: get_sequence(number)
47+
48+
- **number** : arbitrary integer, that need to be calculated in Fibonacci number type
49+
- **Return Value** : return Fibonacci value by specified number as integer
50+
51+
.. function:: get_code()
52+
53+
- **Return Value** : returns the code for the ``get_sequence()`` function

docs/Minumum spanning tree.rst

Lines changed: 0 additions & 25 deletions
This file was deleted.

docs/Searching.rst

Lines changed: 109 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Searching
44

55
Learning searching algorithms easily!
66

7-
-----------------
87
Quick Start Guide
98
-----------------
109

@@ -18,11 +17,10 @@ Quick Start Guide
1817
# pre-requisite for binary search is that the list should be sorted
1918
myList.sort()
2019
21-
# to search en element in the above list
20+
# to search an element in the above list
2221
index = binary_search.search(myList, 7)
2322
print(index)
2423
25-
--------
2624
Features
2725
--------
2826

@@ -32,8 +30,16 @@ Features
3230
- Breadth First Search (breadth_first_search)
3331
- Depth First Search (depth_first_search)
3432

33+
* To see all the available functions in a module there is a `modules()` function available. For example,
34+
35+
.. code:: python
36+
37+
>>> from pygorithm.searching import modules
38+
>>> modules()
39+
['binary_search', 'breadth_first_search', 'depth_first_search', 'linear_search', 'quick_select']
40+
3541
* For Searching:
36-
Remember search() function takes two parameters as a sorted list and the target element to be searched.
42+
Remember ``search()`` function in `binary_search` module takes two parameters as a sorted list and the target element to be searched.
3743

3844
.. code-block:: python
3945
@@ -45,7 +51,7 @@ Features
4551
# pre-requisite for binary search is that the list should be sorted
4652
myList.sort()
4753
48-
# to search en element in the above list
54+
# to search an element in the above list
4955
index = binary_search.search(myList, 7)
5056
print(index)
5157
@@ -66,3 +72,101 @@ Features
6672
6773
# for printing the source code of bubble_sort
6874
print(binary_search.get_code())
75+
76+
77+
Binary Search
78+
-------------
79+
80+
* Functions and their uses
81+
82+
.. function:: binary_search.search(List, key)
83+
:module: pygorithm.searching
84+
85+
- **List** : *Sorted* list in which the key is to be searched
86+
- **key** : key to be searched in the list
87+
- **Return Value** : returns the position (index) of the key if key found, else returns -1
88+
89+
.. function:: binary_search.time_complexities()
90+
91+
- **Return Value** : returns time complexities (Best, Average, Worst)
92+
93+
.. function:: binary_search.get_code()
94+
95+
- **Return Value** : returns the code for the ``binary_search.search()`` function
96+
97+
Linear Search
98+
-------------
99+
100+
* Functions and their uses
101+
102+
.. function:: linear_search.search(List, key)
103+
104+
- **List** : the list in which item is to searched
105+
- **key** : key to be searched in the list
106+
- **Return Value** : returns the position (index) of the key if key found, else returns -1
107+
108+
.. function:: linear_search.time_complexities()
109+
110+
- **Return value** : returns time complexities (Best, Average, Worst)
111+
112+
.. function:: linear_search.get_code()
113+
114+
- **Return Value** : returns the code for the ``linear_search.search()`` function
115+
116+
Breadth First Search
117+
--------------------
118+
119+
* Functions and their uses
120+
121+
.. function:: breadth_first_search.search(graph, startVertex)
122+
123+
- **graph** : takes the graph data structures with edges and vertices
124+
- **startVertex** : it tells the function the vertex to start with
125+
- **Return Value** : returns the `set` of bfs for the ``graph``
126+
127+
.. function:: breadth_first_search.time_complexities()
128+
129+
- **Return Value** : returns time complexities
130+
131+
.. function:: breadth_first_search.get_code()
132+
133+
- **Return Value** : returns the code for the ``breadth_first_search.search()`` function
134+
135+
Depth First Search
136+
------------------
137+
138+
* Functions and their uses
139+
140+
.. function:: breadth_first_search.search(graph, start, path)
141+
142+
- **graph** : takes the graph data structures with edges and vertices
143+
- **start** : it tells the function the vertex to start with
144+
- **path** : returns the list containing the required dfs
145+
- **Return Value** : returns the `list` of dfs for the ``graph``
146+
147+
.. function:: breadth_first_search.time_complexities()
148+
149+
- **Return Value** : returns time complexities
150+
151+
.. function:: breadth_first_search.get_code()
152+
153+
- **Return Value** : returns the code for the ``depth_first_search.search()`` function
154+
155+
Quick Select Search
156+
------------------
157+
158+
* Functions and their uses
159+
160+
.. function:: quick_select.search(array, n)
161+
162+
- **array** : an unsorted array
163+
- **n** : nth number to be searched in the given `array`
164+
- **Return Value** : returns the nth element
165+
166+
.. function:: quick_select.time_complexities()
167+
168+
- **Return Value** : returns time complexities
169+
170+
.. function:: quick_select.get_code()
171+
172+
- **Return Value** : returns the code for the ``quick_select.search()`` function

0 commit comments

Comments
 (0)