How to write a Binary Search Tree program in Python 3, including insert, find, preorder, postorder, and inorder traversal functions, with example BST code implementation. Get the code, which includes the remove function, from my github site here:

www.github.com/joeyajames/Python

This is a very useful tutorial, thanks !

first github download that executed without any errors FIRST TIME! thank you!!!!

Hi Joe Thanks for the great video on BST,

I have one doubt tho, at 1.50-2.00 you mentioned that insert is now called on the root node which is in the Node class. But i am seeing the root node defined in Tree class and not in Node class. Please explain where I am getting this wrong. Thanks a lot in advance!! 😀

thank's!!!

Very concise tutorial! Thanks!

Great tutorial! Question: why didn't you just write the insert function inside the tree class?

plzzz make video on avl bst… plzzz thankx in advance

Very helpful thank you sir!

why return self.rightchild.insert? why not just self.rightchild.insert ? We aren't returning a value we just want the recusion of the function. that return statement is throwing me

This is great.

I have one question. Do you have function to get the level of the element in bst, or return -1 if element isn't in the tree?

Great Video Joe! I'm having a hard time understanding how preorder, postorder and inorder works though. Can you explain that a bit?

why there is no need of return self.left.preorder() for recursion and required return statement in else recursion cases?

Thank you sir for the great set of videos. Please, can you explain what's the benefit of having 2 classes in this case?

That intro tho… 😀

Hi Joe! I am having doubt in code line number 19 (insert function called recursively) since there are 2 insert functions one in node class and other one in tree class. how will this insert function refers to node class?. any help is highly appreciated ! Thanks in advance

It is saying I have no root in the Tree class which is not true been through everything and seems to be correct. Am I

using the wrong version of Python or something.

+Joe James How can i find the height of the tree?

It was a nice video and easily understandable

But there are some repetition for some values in the result for postorder and inorder

can u help please

Thank you so much, save my time 😉

how to implement this

Tasks:

Implement a binary search tree

class BSTree(object):

''' Implement a binary search tree.

Each method you need to implement has its own docstring

with further instruction. You'll want to move most of the

implementation details to the Node class below.

Additionally, keep count of the total number of Trees created

and the number of Nodes in each tree. Include a class method,

"num_trees" to return the former.

'''

def

_init_(self):pass

def

_str_(self):''' Return a representation of the tree as ({left} {elem} {right})

where elem is the element stored in the root, and left and right

are the left and right subtrees (which print out similarly).

Empty trees should be represented by underscores.

'''

pass

def

_len_(self):''' Returns the number of nodes in the tree.'''

pass

def

_contains_(self, element):''' Finds whether a given element is in the tree.

Returns True if the element is found, else returns False.

'''

def insert(self, element):

''' Insert a given value into the tree.

Our implementation will allow duplicate nodes. The left subtree

should contain all elements <= to the current element, and the

right subtree will contain all elements > the current element.

'''

pass

def elements(self):

''' Return a list of the elements visited in an inorder traversal:

http://en.wikipedia.org/wiki/Tree_traversal

Note that this should be the sorted order if you've inserted all

elements using your previously defined insert function.

'''

pass

class Node(object):

''' A Node of the BSTree.

Important data attributes: value (or element), left and right.

'''

pass

def main():

pass

if

_name_== "__main__":main()

how can a user insert? and add minimum is 10 and maximum is 20?

for ex.

me = int(input("Enter a number: "))

i got confused with it. tnx

I was about to ask about the remove/delete functionality, but I see you added part 2. cool. great videos. Thank you.

How do you find a number of a "visited" nodes? Let's say it travels through few nodes and I need to make a function that tells me how many nodes (paths) it took to get there. Also I need to find a minimum and maximum of these path (or should I say levels?)

Anyway thank you for this video, it ACTUALLY help me understand it.

I finally posted the BST part 2 video that shows how to remove/delete, and I posted the code on my github site here, https://github.com/joeyajames/Python. The part 2 video is here, https://www.youtube.com/watch?v=LSju119w8BE

It's very helpful for me.

But I think you should add the "delete node" method.

wow this was so helpful!!

make a video on how to delete a node with no children, a node with one child and a node with 2 children?

where are these values added , there is no list??

Crisp and clear.Thanks

How about deleting a value?

Thanks for sharing, I enjoyed learning it as refresh course in Computer Science.