Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
90ca00a
first part of BST, init class.
chelseadole Nov 24, 2017
4a5a47f
changes to BST, changing depth calculation.
chelseadole Nov 24, 2017
832b109
changes to bst, first traversal methods.
chelseadole Nov 24, 2017
0b26b1f
preorder gen traversal.
chelseadole Nov 24, 2017
498a807
post_order
chelseadole Nov 24, 2017
1c0b988
bredth_first
chelseadole Nov 24, 2017
806f991
finishing breadth first and post order gen.
chelseadole Nov 24, 2017
116a52f
adding tests
chelseadole Nov 24, 2017
7c7b83e
adding 8 new tests for BST edge cases.
chelseadole Nov 24, 2017
5e219b1
fixing small error in BST tests.
chelseadole Nov 24, 2017
1cd5bc0
last changes
chelseadole Nov 24, 2017
bd0e281
adding tests Nathan and I wrote on Friday.
chelseadole Nov 26, 2017
06f48b7
small changes to naming of tests and docstrings to be more semantic.
chelseadole Nov 26, 2017
d46e7be
moving and changing sample trees
chelseadole Nov 26, 2017
6184767
last commit, further semantic changes
chelseadole Nov 26, 2017
7f33e61
first part of README.
chelseadole Nov 26, 2017
05ea5d1
completing README with runtime of all functions.
chelseadole Nov 26, 2017
2a53b96
adding tox, tox.ini, and setup.py as required by tox.
chelseadole Nov 26, 2017
dec712d
adding if __name__ is main at bottom of BST.
chelseadole Nov 26, 2017
a054665
getting rid of duplicate test_bst file outside of src/ directory.
chelseadole Nov 26, 2017
2271aa9
last delete changes.
chelseadole Dec 3, 2017
c8829b4
adding balance(). updated version, using _reassess depths.
chelseadole Dec 4, 2017
634f1e2
updating depth() fn.
chelseadole Dec 4, 2017
bb39064
adding new version of _locate_replacement node
chelseadole Dec 4, 2017
51d179a
adding OG rebalance, none of that re-re shit.
chelseadole Dec 4, 2017
10c4d38
actually reworking rebalance, i think i messed it up.
chelseadole Dec 4, 2017
c41458f
JK. Adding changes we made during code review on thurs, and putting l…
chelseadole Dec 4, 2017
b42566d
adding rotate left
chelseadole Dec 4, 2017
5993eb2
adding rotate left, basically a reflection of rotate right
chelseadole Dec 4, 2017
ec64c36
just discovered that i was adding changes to the wrong bst file, so i…
chelseadole Dec 4, 2017
2fb2675
deleting old BST version.
chelseadole Dec 4, 2017
026f4c4
fixed tree_size, replacing two lines.
chelseadole Dec 4, 2017
a1b0e7b
adding last few tests for delete() BST method.
chelseadole Dec 4, 2017
def40da
deleting corpse code.
chelseadole Dec 4, 2017
f9e47ff
adding README info, runtime.
chelseadole Dec 4, 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
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,38 @@
# data-structures
Data Structures in Python. Code Fellows 401.
# Data-Structures

**Author**: Chelsea Dole

**Resources/Shoutouts**: Nathan Moore (lab partner/amigo)

**Testing Tools**: pytest, pytest-cov

## Data Structures:

* **Binary Search Tree** — *a BST is a "tree shaped" data structure containing nodes. Each node can have a maximum of two children or "leaves," and all node values are properly located based on its parents and siblings values. Nodes to the left of the "root"/head node have values smaller than the root. Those to the right have values larger than the root. There are no duplicate values.*

## Time Complexities:

* balance() = *This BST function returns the balance (or size difference) between the left and right parts of the tree. Its runtime is O(1), because it always takes the same amount of time to run regardless of tree size, and only performs simple subtraction.*

* size() = *This BST function returns the number of nodes/leaves in a tree. Its runtime is O(1), because runtime never changes regardless of tree size. It only returns the value of tree_size, which is created at BST initialization, and changed during the insertion of nodes.*

* insert() = *This BST function inserts a new node into a tree, and uses a helper function called find_home() to find its correctly sorted place in the tree. This function is, depending on the tree, anywhere between O(logn) and O(n), if it's a relatively balanced tree, every decision will reduce the number of nodes one has to traverse. But if it's a one-sided tree, one may look over every node -- making it O(n).*

* search() = *This BST function is a reference to check_for_equivalence(), which is recursive, and has a runtime of O(n^2), because every time you're re-calling check_for_equivalence, it looks at every node's equivalence.*

* contains() = *This BST function looks at search(), described above, and for the same reasons has runtime of O(n^2).*

* depth() = *This BST function returns the number of "levels" that the tree has, by finding which of the two sides has the greatest depth, and returning that. It has a runtime of O(1), because no matter the size of the tree, it only performs a comparison operation.*

* in_order() = *This BST traversal function traverses the tree and returns a generator that outputs the node values in numerical order. It has a runtime of O(n), not because you visit every node once (you visit them more than once here) but because the work you do/time you take is constant and grows constantly per node addition.*

* pre_order() = *This BST traversal function returns a generator that outputs the node values in order of the furthest left parent, its left child, then its right child. This traveral then backs up to the parent, and repeats until the whole tree has been traversed. Like in_order, it has a runtime of O(n), not because you visit every node once (you visit them more than once here) but because the work you do/time you take is constant and grows constantly per node addition.*

* post_order() = *This BST traversal function returns a generator that outputs the node values in order of the bottom-most left node, the bottom-most right node, and then those nodes' parent. Then it backs up, and repeats this action with the parent as a new child node, until the whole tree has been traversed. Like in_order and pre_order, it has a runtime of O(n), not because you visit every node once (you visit them more than once here) but because the work you do/time you take is constant and grows constantly per node addition.*

* breadth_first() = *This BST traversal returns a generator that outputs the node values in order of their "levels". It produces first the root, then all nodes (left to right) in the first depth level, then all nodes (left to right) in the second depth level, et cetera. Like in_order, pre_order, and post_order, it has a runtime of O(n), not because you visit every node once (you visit them more than once here) but because the work you do/time you take is constant and grows constantly per node addition.*

* delete() = *This BST method deletes a node if it exists, and returns None if it does not exist. It also rebalances the BST (using the internal _rebalance() method, and resets variables for tree_size. Its time complexity is O(n), because worst case scenario the node to delete is at the very end of a imbalanced tree, and therefore it must go through every node.*



15 changes: 15 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Setup module for Chelsea's data structures."""

from setuptools import setup

setup(
name='Data structures',
description='Various data structures in python',
author='Chelsea Dole',
author_email='chelseadole@gmail',
package_dir={' ': 'src'},
py_modules=['bst'],
install_requires=['timeit'],
extras_require={
'test': ['pytest', 'pytest-cov', 'pytest-watch', 'tox'],
'development': ['ipython']})
Loading