Conversation
…o bst Merging branch bst.
…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
…ures into balance-bst ng tests for left and right rotations.#
…ures into balance-bst merging branch.
… branch 'balance-bst' of https://github.com/chamberi/data-structures into balance-bst
| """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.""" | ||
|
|
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
When this gets called, are you passing an entire tree in each tine or only a single node?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
A tree can be represented by its root node as the root node contains pointers to the trees below it
There was a problem hiding this comment.
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.""" |
There was a problem hiding this comment.
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
No description provided.