Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
04fa77e
Done with binheap
Oct 31, 2017
3f009ca
reworked push and working on pop, also wrote some tests
markreynoso Nov 2, 2017
1d1137a
completed readme, added setup, added tox, fixed push and pop, finishe…
markreynoso Nov 2, 2017
d36c245
initial setup
Nov 3, 2017
d98d517
Merge branch 'priorityq' of https://github.com/chaitanyanarukulla/dat…
markreynoso Nov 3, 2017
9380413
untested priority heap written. works great in theory.
markreynoso Nov 3, 2017
0881f6c
fixed insert and pop methods and wrote a few tests, all passing
markreynoso Nov 3, 2017
f094873
Test written and passing all test
Nov 5, 2017
ac42137
created graph
markreynoso Nov 5, 2017
d75d601
git issue
Nov 5, 2017
03b0444
Writing test
Nov 6, 2017
2c6e481
test are passing
Nov 6, 2017
bc22f46
tests passing and cleaned up code
markreynoso Nov 6, 2017
b244da2
depth first tested and finished
markreynoso Nov 7, 2017
69d06da
implemented breadth_first_traversal and depth_first_traversal functio…
Nov 7, 2017
9b64dc2
tested for cyclic graphs
Nov 7, 2017
a73a4b1
converted graph to dictionaries and added weight to edges
markreynoso Nov 8, 2017
12f72b6
refactored tests for python 2
markreynoso Nov 8, 2017
67c69e5
added testing for weights of edges
markreynoso Nov 9, 2017
0700ebc
updated readme
markreynoso Nov 9, 2017
b9c8b6f
added if name=main and adjusted for new dictionary setup
markreynoso Nov 9, 2017
ad445ab
for loop over q not working, changing size mid loop not working
markreynoso Nov 12, 2017
f8bab38
refactoring back to priority q
markreynoso Nov 19, 2017
7ed931d
shortest path working
markreynoso Nov 19, 2017
c8ab7c3
fixed no children error
markreynoso Nov 19, 2017
8ed41a1
changed filename to match
markreynoso Nov 19, 2017
b6897ad
Updated Test for Shortest_dis
chaitanyanarukulla Nov 19, 2017
640d548
tested Shortest distance
chaitanyanarukulla Nov 19, 2017
b467ebc
updated readme
markreynoso Nov 19, 2017
59540c5
insert, search, size done in bst
markreynoso Nov 21, 2017
4fe4752
rough bst completed, no tests
markreynoso Nov 21, 2017
cf5f4ec
tested bst and all tests pass
markreynoso Nov 21, 2017
672e83e
added if name is main
markreynoso Nov 21, 2017
3230112
refactored insert and search
markreynoso Nov 21, 2017
1e41236
timeit works once
markreynoso Nov 22, 2017
6826163
added print times comparisons
markreynoso Nov 22, 2017
7c30144
breadth and in order
markreynoso Nov 23, 2017
47f50af
started pre order
markreynoso Nov 23, 2017
5e9ab82
pre order done and tested, post order in process
markreynoso Nov 23, 2017
094d8f6
pre, post, breadth, and in order finished and tested
markreynoso Nov 24, 2017
49a9153
added travis ci integration
markreynoso Nov 24, 2017
aaa7b0c
added travis ci integration
markreynoso Nov 24, 2017
f0763a4
added travis badge
markreynoso Nov 24, 2017
5dbeca2
delete working and tested
markreynoso Nov 28, 2017
9cf2ed8
added delete to readme
markreynoso Nov 28, 2017
3adc12c
refactored delete, added parent assignment to one child and removed u…
markreynoso Nov 29, 2017
43bcdb7
fixed delete glitch with parent issue
markreynoso Dec 2, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: python
python:
- "2.7"
- "3.6"
install:
- pip install .
- pip install -r requirements.txt
script: py.test
275 changes: 273 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,273 @@
# data-structures
Data-Structures
# Data-Structures

[![Build Status](https://travis-ci.org/markreynoso/data-structures.svg?branch=bst_traversals)](https://travis-ci.org/markreynoso/data-structures)

Where a variety of data-structures found in python are being explored, such as:
* A simple class LinkedList for building linked lists as well as a subclass Stack to implement a stack.

## Authors

ChaiChaitanya Narukulla and Mark Reynoso created this code base as a project for Python 401 at Code Fellows Seattle.

### Requirements for testing and development

In order to create a development and testing environment, you will need the following:

```
python2, python3, ipython, pytest, pytest-watch, pytest-cov, tox
```

```
To install environment:

pip install -e .[testing][development]
```

### Linkded List Class Usage

```
To create an instance of a the LinkedList() class contained in package, from python:

new = LinkedList() *you may choose and optional parameter of a single value or an iterable of one of the following: a tuple, a list, or a string.*

LinkedList() contains the following methods:
* _push(val) (O1)_ - will insert the value ‘val’ at the head of the list.
* _pop() (O1)_ - will pop the first value off the head of the list and return it. Raises an exception with an appropriate message if there are no values to return.
* _size() (01)_ - will return the length of the list.
* _search(val) (On)_ - will return the node containing ‘val’ in the list, if present, else None.
* _remove(node) (On)_ - will remove the given node from the list, wherever it might be (node must be an item in the list). If the node is not in the list, it will raise an exception with an appropriate message.
* _display() (O1)_ - will return a unicode string representing the list as if it were a Python tuple literal: “(12, ‘sam’, 37, ‘tango’)”

To access any contained methods:
new.push(val)
new.pop()
new.size()
new.search(val)
new.remove(node)
new.display()

Additionally, LinkedList() will interact with these built-in Python functions:

* _len(new)_ - returns the size of the list.
* _print(new)_ - returns what the display() method returns.

```

### Stack Class Usage

```
To create an instance of a Stack() class contained in package, from python:

new = Stack() *you may choose and optional parameter of a single value or an iterable of one of the following: a tuple, a list, or a string.*

Stack() contains the following methods:
* _push(val) (O1)_ - will insert the value ‘val’ at the head of the stack.
* _pop() (O1)_ - will pop the first value off the head of the stack and return it. Raises an exception with an appropriate message if there are no values to return.

To access any contained methods:
new.push(val)
new.pop()

Additionally, Stack() will interact with these built-in Python functions:

* _len(new)_ - returns the size of the list.

```

### Doubly Linked List Class Usage

```
To create an instance of a Dll() class contained in package, from python:

new = Dll() *you may not call Dll() with any parameters.*

Dll() contains the following methods:
* _push(val) (O1)_ - will insert the value ‘val’ at the head of the list.
* _append(val) (O1)_ - will insert the value ‘val’ at the tail of the list.
* _pop() (O1)_ - will pop the first value off the head of the stack and return it. Raises an exception with an appropriate message if there are no values to return.
* _shift() (O1)_ - will remove the last value off the tail of the list and return it. Raises an exception with an appropriate message if there are no values to return.
* _remove(node) (On)_ - will remove the given node from the list, wherever it might be (node must be an item in the list). If the node is not in the list, it will raise an exception with an appropriate message.

To access any contained methods:
new.push(val)
new.append(val)
new.pop()
new.shift()
new.remove()

Additionally, Dll() will interact with these built-in Python functions:

* _len(new)_ - returns the size of the list.

```

### Queue Class Usage

```
To create an instance of a Queue() class contained in package, from python:

new = Queue() *you may not call Queue() with any parameters.*

Queue() contains the following methods:
* _enqueue(val) (O1)_ - will insert the value ‘val’ at the end of the queue.
* _dequeue() (O1)_ - will remove the last value off the front of the queue and return it. Raises an exception with an appropriate message if there are no values to return.
* _peek() (O1)_ - shows the value of the node at the end of the queue.
* _size() (O1)_ - displays the number of node in the queue.

To access any contained methods:
new.enqueue(val)
new.dequeue()
new.peek()
new.size()

Additionally, Queue will interact with these built-in Python functions:

* _len(new)_ - returns the size of the list.

```

### Deque Class Usage

```
To create an instance of a Deque() class contained in package, from python:

new = Deque() *you may not call Deque() with any parameters.*

Deque() contains the following methods:
* _append(val) (O1)_ - will insert the value ‘val’ at the end of the deque.
* _appendleft() (O1)_ - will insert a value to the front of the deque.
*_pop() (01)_ - removes the first val from the end of the deque.
*_popleft() (01)_ - removes the first val from the front of the deque.
* _peek() (O1)_ - shows the value of the item at the end of the deque.
* _peekleft() (O1)_ - shows the value of the item at the font of the deque.
* _size() (O1)_ - displays the number items in the deque.

To access any contained methods:
new.append(val)
new.appendleft(val)
new.pop()
new.popleft()
new.peek()
new.peekleft()
new.size()

```

### Binaary Heap (Binheap) Class Usage

```
To create an instance of a Binheap() class contained in package, from python:

new = Binheap() *you may call Binheap() with any uniqe number or iterable of unique numbers.*

Binheap() contains the following methods:
* _push(val) (Olog(n))_ - will insert the value ‘val’ at the end of the heap.
*_pop() (0log(n))_ - removes the first val from the end of the heap.

To access any contained methods:
new.push(val)
new.pop()

```

### Priorityq (Priorityq) Class Usage

```
To create an instance of a Priorityq() class contained in package, from python:

new = Priorityq() *you may call Priorityq() with any uniqe number or iterable of unique numbers.*

Priorityq() contains the following methods:
*_insert(val,priority) (O1)_ - will insert the value ‘val’ at the end of the heap.
*_pop() (01)_ - removes the higest priority and returns the higest priority.
*_peek() (01)_ - returns the higest priority.

To access any contained methods:
new.insert(val)
new.pop()
new.peek()

```

### Graph Class (weighted) Usage

```
To create an instance of a Graph() class contained in package, from python:

new = Graph() *you may not call Graph() with any parameters.*

Graph() contains the following methods:
* _nodes() (O1)_ - will return a list of all nodes in the graph.
* _edges() (On2)_ - will return a dictionary of edges in graph with weights.
*_add_node(val) (01)_ - adds a new node to the graph.
*_add_edge(val1, val2, weight) (0n)_ - add a new edge to nodes in the graph.
* _del_node(val) (On2)_ - delete node from graph.
* _del_edge(val1, val2) (On)_ - delete edge between two nodes.
* _has_node(val) (O1)_ - returns true if node exists and false if not.
* _neighbors(val) (On2)_ - return a list of nodes with edges to input node.
* _adjacent(val1, val2) (On)_ - return true if edge exists between two inputs,
otherwise false.
* _depth_first_traversal(start_val) (Ologn)_ - will return full visited path of traversal completed.
* _breadth_first_traversal(start_val)(Ologn)_ - will return full visited path of traversal completed.

To access any contained methods:
new.nodes()
new.edges()
new.add_node(val)
new.add_edge(val1, val2, weight)
new.del_node(val)
new.del_edge(val1, val2)
new.has_node(val)
new.neighbors(val)
new.adjacent(val1, val2)
new.depth_first_traversal(start_val)
new.breadth_first_traversal(start_val)

```

### Shortest Distance Problem

```
The problem of the traveling salesperson finding the shortest distance between points can be solved in a variety of ways. We have used Dijkstra's Algorith as our first method to a solution.

_Dijkstra's Algorithm_ (On) - finds the shortest path exploring all edges of a graph from it's starting point. By comparing the distance or weight of the edges from the start to each child as it traverses the graph it is able to calculate the shortest route by saving the parent path which will have the lowest cost from start to finish.

To use this function:
dijkstra(graph, start, end)

```

### Binary Search Tree

```
To create an instance if the binary search tree, Bst(), from python:

new = Bst() *you may not call Bst() no parameters or with an iterable item containing unique integers.*

Bst() contains the following methods:
* _insert(val) (Olog(n))_ - will insert the value ‘val’ in the appropriate position in the tree.
* _search(val) (0log(n))_ - will find a given value in the tree, if not in tree will return none.
* _size() (O(1))_ - will return the size of the tree.
* _depth(root) (0(n))_ - returns the depth of the tree.
* _contains(val) (Olog(n))_ - will return true or false if value is in tree.
*_ balance() (0(n))_ - returns the depth of the left minus the right side of the tree as an integer.
* _in_order() (O(n))_ - returns a generator the entire tree in order of lowest to highest value.
* _pre_order() (0(n)(log(n)))_ - returns a generator of parent followed by children from left side to right side.
* _post_order() (O(n)log(n)))_ - returns a generator of children followed by parent from left side to right side.
*_ breadth_first() (0(n))_ - returns generator of tree ordered from root one level at a time.
*_ delete(val) (0log(n))_ - delete a node with given val.


To access any contained methods:
new.insert(val)
new.search(val)
new.size()
new.depth(root)
new.contains(val)
new.balance()
new.in_order()
new.pre_order()
new.post_order()
new.breadth_first()
new.delete(val)
```
29 changes: 29 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
appnope==0.1.0
argh==0.26.2
colorama==0.3.9
coverage==4.4.2
-e git+https://github.com/markreynoso/data-structures.git@094d8f6f7f5c7e9af06a5e4442a872acbe11c94f#egg=data_structures
decorator==4.1.2
docopt==0.6.2
ipython-genutils==0.2.0
jedi==0.11.0
parso==0.1.0
pathtools==0.1.2
pexpect==4.3.0
pickleshare==0.7.4
pluggy==0.5.2
prompt-toolkit==1.0.15
ptyprocess==0.5.2
py==1.5.2
Pygments==2.2.0
pytest==3.2.5
pytest-cov==2.5.1
pytest-watch==4.1.0
PyYAML==3.12
simplegeneric==0.8.1
six==1.11.0
tox==2.9.1
traitlets==4.3.2
virtualenv==15.1.0
watchdog==0.8.3
wcwidth==0.1.7
16 changes: 16 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from setuptools import setup

setup(
name='data-structures',
description=('A package for building and '
'running the data-structures module'),
package_dir={'': 'src'},
author='Mark and chai',
author_email='chaitanyanarukulla@gmail.com mreynoso@spu.edu',
py_modules=['binheap'],
install_requires=[],
extras_require={
'testing': ['pytest', 'pytest-cov', 'pytest-watch', 'tox'],
'development': ['ipython']
},
)
Loading