Python3 BST developed for HackerRank Challenges
-Fastest would be to copy-paste the contents of DisjointSet.py into your code. As this was made for HR challenges that's what I do.
-Or you could download BinarySearchTree.py and throw it in your project directory. Use "from BinarySearchTree import *" to use it in your code
-You could clone https://github.com/asawitt/PythonBinarySearchTree/ , move BinarySearchTree.py to your project directory, then use the above import statement if you really want to. Don't.
Insert, Delete, Find run in O(log(n)) average, O(n) worst case. Operations on unbalanced trees will take longer, considering this, if your data is highly sequential it's recommended you use a self-balancing tree such as AVL or Red-Black trees
tree = BST()
tree.insert(value)
tree.delete(value)
-Returns True if the value is in the Tree, False otherwise tree.find(value)
-Prints the tree, layer-by-layer
tree.printTree()
-Returns a list of the values in the BST from least to greatest
tree.flatten()
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.