Skip to content

Conversation

@chamberi
Copy link
Owner

No description provided.

CCallahanIV and others added 30 commits January 16, 2017 12:44
…o bst

sdf building a binary search tree.
…ctures into traversal-bst

g
g Lines starting with '#' will be ignocquire post_order_trav. red, and an empty message aborts
William Benjamin Shields and others added 22 commits January 23, 2017 15:43
…ures into balance-bst

ng tests for left and right rotations.#
"""pre_order(self): will return a generator that will return the values in the tree using pre-order traversal, one at a time."""
"""post_order(self): will return a generator that will return the values in the tree using post_order traversal, one at a time."""
"""breadth_first(self): will return a generator that will return the values in the tree using breadth-first traversal, one at a time."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be missing a method here. Also you don't need to wrap every line in the """, just once at the beginning and once and once at the end.

if (vertex.right):
q.enqueue(vertex.right)

def delete(self, val):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to break...

In [2]: bst = BinarySearchTree()

In [3]: bst.insert(1)

In [4]: bst.insert(0.5)

In [5]: bst.delete(0.5)
---------------------------------------------------------------------------
AttributeError: 'NoneType' object has no attribute 'value'

donated.
The user can add a donor name to this list.
The user can quit the program from Main Menu, and
may return to Main Menu at any time.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that the hash table tracks donations and writes tailored thank you emails...

"""
return self._calc_depth(self.root)

def _calc_depth(self, tree):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this gets called, are you passing an entire tree in each tine or only a single node?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We thought it was the entire tree because its recursive and the node contains pointers to every node below it, so in a way its the entire tree as well as a single node

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A tree can be represented by its root node as the root node contains pointers to the trees below it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could change it though. It might be better to be completely consistent with naming conventions, either having nodes being called nodes or nodes being called trees every time.

q.enqueue(vertex.right)

def delete(self, val):
"""Remove val from the tree if present, if not present this method is a no-op. Return None in all cases."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to break...

In [2]: bst = BinarySearchTree()

In [3]: bst.depth()
Out[3]: 0

In [4]: bst.insert(9)

In [5]: bst.insert(8)

In [6]: bst.insert(7)

In [7]: bst.insert(6)

In [8]: bst.depth()
Out[8]: 4

In [9]: bst.delete(8)

In [10]: bst.depth()
Out[10]: 1

In [11]: bst.contains(7)
Out[11]: False

In [12]: bst.contains(9)
Out[12]: True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants