Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 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
4c07280
fixed depth and started self balancing
markreynoso Nov 29, 2017
14b622a
fixed depth and balance
markreynoso Nov 29, 2017
5b36b32
refactored delete with one child to account for parent
markreynoso Nov 29, 2017
d729b92
working on rotations
markreynoso Nov 30, 2017
35bce3a
first test for self balancing done and passing!
markreynoso Nov 30, 2017
df4ebd7
self balancing tests passing so far
markreynoso Dec 1, 2017
bd11c4f
self-balancing working and tested
markreynoso Dec 2, 2017
fcbc6ad
simple hash working
markreynoso Dec 3, 2017
139d32f
horner hash added, tests complete and passing
markreynoso Dec 3, 2017
0ea7ca5
trie working, save delete which is unfinished
markreynoso Dec 4, 2017
27c4488
all tests passing, refactored search
markreynoso Dec 4, 2017
1b246cf
updated readme
markreynoso Dec 4, 2017
4ddd509
fixed issues with graph
markreynoso Dec 4, 2017
0360158
adjusted binheap
markreynoso Dec 5, 2017
729eafa
updated priorityq
markreynoso Dec 5, 2017
56e5939
fixed edges to list
markreynoso Dec 5, 2017
5632415
fixed graph
markreynoso Dec 5, 2017
82a3e9b
fixed binheap
markreynoso Dec 5, 2017
e263a18
moved shortest distance to graph
markreynoso Dec 5, 2017
f1f2f8a
removed else statement not needed
markreynoso Dec 5, 2017
2b24a5e
added catch for contains if not string entered
markreynoso Dec 5, 2017
6617d45
removed else in remove
markreynoso Dec 5, 2017
b7b0a67
updated neighbors
markreynoso Dec 6, 2017
3b0fbd7
refactored tests for python 2
markreynoso Dec 6, 2017
c347521
starting traversal
markreynoso Dec 7, 2017
b776c34
bubble sort, tests, and readme
markreynoso Dec 7, 2017
a337625
setting up insert sort
markreynoso Dec 8, 2017
c75d0db
insert method finished and tests passing
markreynoso Dec 8, 2017
13a9aa7
merge sort done and tested
markreynoso Dec 10, 2017
3e74b51
quick sort has bug
markreynoso Dec 11, 2017
f13758b
quick sort working and tested
markreynoso Dec 12, 2017
646df7f
radix finished and tests passing
markreynoso Dec 12, 2017
d078ec7
replaced list in name=main
markreynoso Dec 13, 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
377 changes: 375 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,375 @@
# 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 (min-heap) 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)

```

### Self-Balancing Binary Search Tree

```
Tree will maintain a balance of no more that 1 or -1 and will automatically rebalance on any insert or delete into the tree using the methods described below.

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)
```

### Hash Table

```
Using a naive hash and slightly more complex hash with Horner's Rule, HashTable() will store based on the supplied key, which must be a string. By default, HashTable() uses the naive hash method, but can be changed on initialization.

To create an instance if the hash table, HashTable(), from python:

new = HashTable() *you may initiate the table with any size, must be integer, as the first arguement in the function. You may also pass in an alternative hashing method. A naive hash will be used my defaul, but you may also choose `horner_hash` as the second arguement on initialization, or any hashing function you choose to import. For example: HashTable(100000, horner_hash).*

HashTable() contains the following methods:
* _set(key, val) (O(n))_ - sets a value at a given key (must me string) in the table, if key already has value it will be set to new value.
* _get(key) (0(n))_ - retrieve the value of the item with the given key.
* _ _hash(key) (O(n))_ - hashes key and returns an integer between 0 and the size of the table.

To access any contained methods:
new.set(key, val)
new.get(key)
```

### Trie

```
In order to efficiently store words, Trie() will provide a class by which nodes are only inserted if unshared by anthor word. All words share previous characters when possible.

To create an instance if the trie, Trie(), from python:

new = Trie() *you may not initiate the trie with any values.*

Trie() contains the following methods:
* _insert(string) (O log(n))_ - inserts a new node for every letter in string (input must be word) if not able to share with another word.
* _contains(string) (0 log(n))_ - returns True if word is in trie and False if not.
* _size() (O(1))_ - retruns the number of words in the trie.
* _remove(string) (O log(n))_ - removes word from trie and raises error if word not in trie.

To access any contained methods:
new.insert(string)
new.contains(string)
new.size()
new.remove(string)
```

### Bubble Sort

```
Bubble sort takes in a list of numbers and uses a bubble sort method to return a sorted list.

To use bubble_sort, from bubble_sort import bubble_sort.
Pass in a list of numbers bubble_sort(list).

* _bubble_sort(list) (O(n^2))_

```

### Insert Sort

```
Insert sort takes in a list of numbers and uses an insert sort method to return a sorted list.

To use insert_sort, from insert_sort import insert_sort.
Pass in a list of numbers insert_sort(list).

* _insert_sort(list) (O(n^2))_

```

### Merge Sort

```
Merge sort takes in a list of numbers and uses an merge sort method to return a sorted list.

To use merge_sort, from merge_sort import merge_sort.
Pass in a list of numbers merge_sort(list).

* _merge_sort(list) (O(n log(n)))_

```

### Quick Sort

```
Quick sort takes in a list of numbers and uses an quick sort method to return a sorted list.

To use quick_sort, from quick_sort import quick_sort.
Pass in a list of numbers quick_sort(list).

* _quick_sort(list) (O(n log(n)))_

```

### Radix Sort

```
Radix sort takes in a list of numbers and uses an radix sort method to return a sorted list.

To use radix_sort, from radix_sort import radix_sort.
Pass in a list of numbers radix_sort(list).

* _radix_sort(list) (O(n * k))_

```
Loading