Skip to content

Commit f0cc61f

Browse files
committed
Merge docs/index.rst
2 parents b7a63fb + 04c254e commit f0cc61f

File tree

10 files changed

+281
-31
lines changed

10 files changed

+281
-31
lines changed

docs/DynamicP.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
===================
2+
Dynamic Programming
3+
===================
4+
5+
A place for implementation of greedy algorithms
6+
7+
Features
8+
--------
9+
10+
* To see all the available functions in a module, you can just type ``help()`` with the module name as argument. For example,
11+
12+
.. code:: python
13+
14+
>>> from pygorithm import greedy_algorithm
15+
>>> help(greedy_algorithm)
16+
Help on package pygorithm.dynamic_programming in pygorithm:
17+
18+
NAME
19+
pygorithm.dynamic_programming - Collection for dynamic programming algorithms
20+
21+
PACKAGE CONTENTS
22+
binary_knapsack
23+
lis
24+
25+
DATA
26+
__all__ = ['binary_knapsack', 'lis']
27+
28+
29+
Binary (0/1) Knapsack
30+
---------------------
31+
32+
* Functions and their uses
33+
34+
.. automodule:: pygorithm.dynamic_programming.binary_knapsack
35+
:members:
36+
37+
Longest Increasing Subsequence
38+
------------------------------
39+
40+
* Functions and their uses
41+
42+
.. automodule:: pygorithm.dynamic_programming.lis
43+
:members:

docs/Greedy.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
=================
2+
Greedy Algorithms
3+
=================
4+
5+
A place for implementation of greedy algorithms
6+
7+
Features
8+
--------
9+
10+
* To see all the available functions in a module, you can just type ``help()`` with the module name as argument. For example,
11+
12+
.. code:: python
13+
14+
>>> from pygorithm import greedy_algorithm
15+
>>> help(greedy_algorithm)
16+
Help on package pygorithm.greedy_algorithm in pygorithm:
17+
18+
NAME
19+
pygorithm.greedy_algorithm - Collection for greedy algorithms
20+
21+
PACKAGE CONTENTS
22+
activity_selection
23+
fractional_knapsack
24+
25+
DATA
26+
__all__ = ['fractional_knapsack', 'activity_selection']
27+
28+
29+
Activity Selection Problem
30+
--------------------------
31+
32+
* Functions and their uses
33+
34+
.. automodule:: pygorithm.greedy_algorithm.activity_selection
35+
:members:
36+
37+
Fractional Knapsack
38+
-------------------
39+
40+
* Functions and their uses
41+
42+
.. automodule:: pygorithm.greedy_algorithm.fractional_knapsack
43+
:members:

docs/index.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ Quick Links
2222
:maxdepth: 2
2323
:caption: Documentation:
2424

25-
Sorting
26-
Searching
2725
Data_Structure
26+
DynamicP
2827
Fibonacci
28+
Greedy
2929
Math
3030
Pathfinding
3131
Geometry
32+
Searching
33+
Sorting
34+
strings
3235

3336
Quick Start Guide
3437
-----------------

docs/strings.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
=======
2+
Strings
3+
=======
4+
5+
A place for implementation of string algorithms
6+
7+
Features
8+
--------
9+
10+
* To see all the available functions in a module, you can just type ``help()`` with the module name as argument. For example,
11+
12+
.. code:: python
13+
14+
>>> from pygorithm import strings
15+
>>> help(strings)
16+
Help on package pygorithm.strings in pygorithm:
17+
18+
NAME
19+
pygorithm.strings - Collection of string methods and functions
20+
21+
PACKAGE CONTENTS
22+
anagram
23+
isogram
24+
manacher_algorithm
25+
palindrome
26+
pangram
27+
28+
29+
Anagram
30+
-------
31+
32+
* Functions and their uses
33+
34+
.. automodule:: pygorithm.strings.anagram
35+
:members:
36+
37+
Isogram
38+
-------
39+
40+
* Functions and their uses
41+
42+
.. automodule:: pygorithm.strings.isogram
43+
:members:
44+
45+
Palindrome
46+
----------
47+
48+
* Functions and their uses
49+
50+
.. automodule:: pygorithm.strings.palindrome
51+
:members:
52+
53+
Pangram
54+
-------
55+
56+
* Functions and their uses
57+
58+
.. automodule:: pygorithm.strings.pangram
59+
:members:
60+
61+
Manacher's Algorithm
62+
--------------------
63+
64+
* Functions and their uses
65+
66+
.. automodule:: pygorithm.strings.manacher_algorithm
67+
:members:

pygorithm/data_structures/linked_list.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def delete(self, data):
118118
# node not found
119119
if temp is None:
120120
return
121-
121+
122122
# TODO: local variable 'prev' might be referenced before assignment
123123
# TODO: Fix this
124124
prev.next = temp.next
@@ -214,3 +214,72 @@ def get_code():
214214
returns the code of the current class
215215
"""
216216
return inspect.getsource(DoublyLinkedList)
217+
218+
class CircularLinkedList(object):
219+
'''
220+
Class for circular linked list
221+
'''
222+
def __init__(self):
223+
self.head = None
224+
self.tail = None
225+
self.size = 0
226+
227+
def clear(self):
228+
''' clears the head and tails of the linked list '''
229+
self.tail = None
230+
self.head = None
231+
232+
def get_data(self):
233+
"""
234+
prints the elements in the linked list
235+
"""
236+
l_list = []
237+
current = self.tail
238+
while True:
239+
l_list.append(current.data)
240+
current = current.next
241+
if current == self.tail:
242+
break
243+
return l_list
244+
245+
def insert(self, data):
246+
''' inserts the data in to the linked list '''
247+
node = Node(data)
248+
if self.head:
249+
self.head.next = node
250+
self.head = node
251+
else:
252+
self.head = node
253+
self.tail = node
254+
self.head.next = self.tail
255+
self.size += 1
256+
257+
def delete(self, data):
258+
''' deletes the specified element from linked list '''
259+
current = self.tail
260+
prev = self.tail
261+
while prev == current or prev != self.head:
262+
if current.data == data:
263+
if current == self.tail:
264+
self.tail = current.next
265+
self.head.next = self.tail
266+
else:
267+
prev.next = current.next
268+
self.size -= 1
269+
return
270+
prev = current
271+
current = current.next
272+
273+
@staticmethod
274+
def get_code():
275+
"""
276+
returns the code of the current class
277+
"""
278+
return inspect.getsource(CircularLinkedList)
279+
280+
if __name__ == '__main__':
281+
cll = CircularLinkedList()
282+
cll.insert(1)
283+
cll.insert(2)
284+
cll.insert(3)
285+
print(cll.get_data())

pygorithm/dynamic_programming/binary_knapsack.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
Created At: 25th August 2017
44
"""
55
import inspect
6-
# TODO: Explain how this works / Explain what a knapsack is
76

87

98
def knapsack(w, value, weight):
109
"""
10+
The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of
11+
items, each with a weight and a value, determine the number of each item to include in a collection
12+
so that the total weight is less than or equal to a given limit and the total value is as large as
13+
possible. It derives its name from the problem faced by someone who is constrained by a fixed-size
14+
knapsack and must fill it with the most valuable items.
15+
1116
:param w: maximum weight capacity
1217
:param value: an array of values of items in the knapsack
1318
:param weight: an array of weights of items in the knapsack

pygorithm/dynamic_programming/lis.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ def longest_increasing_subsequence(_list):
88
"""
99
The Longest Increasing Subsequence (LIS) problem is to find the length of the longest subsequence of a
1010
given sequence such that all elements of the subsequence are sorted in increasing order. For example,
11-
the length of LIS for {10, 22, 9, 33, 21, 50, 41, 60, 80} is 6 and LIS is {10, 22, 33, 50, 60, 80}.
12-
:param _list:
13-
:return:
11+
the length of LIS for [10, 22, 9, 33, 21, 50, 41, 60, 80] is 6 and LIS is [10, 22, 33, 50, 60, 80].
12+
13+
:param _list: an array of elements
14+
:return: returns a tuple of maximum length of lis and an array of the elements of lis
1415
"""
1516
# Initialize list with some value
1617
lis = [1] * len(_list)

pygorithm/greedy_algorithm/activity_selection.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
Created On: 26th August 2017
44
"""
55
import inspect
6-
# TODO: Explain what this is / how it works
76

87

98
def activity_selection(start_times, finish_times):
109
"""
10+
The activity selection problem is a combinatorial optimization problem concerning the selection of
11+
non-conflicting activities to perform within a given time frame, given a set of activities each marked
12+
by a start time (si) and finish time (fi). The problem is to select the maximum number of activities
13+
that can be performed by a single person or machine, assuming that a person can only work on a single
14+
activity at a time.
15+
1116
:param start_times: An array that contains start time of all activities
1217
:param finish_times: An array that conatins finish time of all activities
1318
"""

pygorithm/greedy_algorithm/fractional_knapsack.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
Created On: 22nd August 2017
44
"""
55
import inspect
6-
# TODO: Explain how this works / Explain what a knapsack is
76

87

98
def knapsack(w, item_values, item_weights):
109
"""
10+
The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of
11+
items, each with a weight and a value, determine the number of each item to include in a collection so
12+
that the total weight is less than or equal to a given limit and the total value is as large as
13+
possible. It derives its name from the problem faced by someone who is constrained by a fixed-size
14+
knapsack and must fill it with the most valuable items.
15+
1116
:param w: maximum weight capacity
1217
:param item_values: a list of values of items in the knapsack
1318
:param item_weights: a list of weights of items in the knapsack

0 commit comments

Comments
 (0)