Python Program To Implement Binary Search Tree | Program 7 | Min and Max Key
Вставка
- Опубліковано 2 жов 2024
- In this Python Programming video tutorial you will learn how to implement binary search tree in detail.
Data structure is a way of storing and organising the data so that it can be accessed effectively.
Tree is a non linear data structure contains group of nodes connected via links or edge.
Binary search tree is a special type of binary tree . Here we will use class and object concept to implement binary search tree. In this tutorial we will see how to find minimum and maximum node in tree.
#DataStructures #PythonPrograms #Tree
For more free tutorials on computer programming
/ amulsacademy
AmulsAcademy
Via recursion 👇🏻
def min_node(self):
If self.lchild:
self.lchild.min_node()
elif self.lchild is None:
print("min node :" ,self.key)
This will find also by using recursive function na madam
Yes 😊
Amulya if we want to get the position of an node while searching ,is it possible ? Because In the previous code ,we could only know the key is present in the tree or not ,but we couldn't know the position of the key
def minimum(self):
if self.lchild==None:
return self.key
else:
self.lchild.minimum()
def maximum(self):
if self.rchild==None:
return self.key
else:
self.rchild.maximum()
mam i have written this code!
mam we need to apply break statement to terminate the while loop
def min(self):
current=self
while current.left:
current=self.left
break
print('the min is: ',current.root)
def max(self):
current=self
while current.right:
current=self.right
break
print('the max is:',current.root)
Thank you so much for wonderful content.😎👌👌🙌🙌🙌
mam can you please implement it and explain it?please mam if possible , and mam you are also not uploading any videos
Will try 😊
why we didnt write current = self.key except self
what will happen when tree is empty
you are amazing 🤩
def min_node(self):
current=self
while current.lchild:
current=self.lchild
print("The min value in the tree is",current.key)
def max_node(self):
current=self
while current.rchild:
current=self.rchild
print("The max value in the tree is",current.key)
infinite loop coming is mam
you need to use current.lchild in 4th line instead of self.lchild becz self value in not changing, same for max_node function.
def min(self):
current=self
while current.left:
current=self.left
break
print('the min is: ',current.root)
def max(self):
current=self
while current.right:
current=self.right
break
print('the max is:',current.root)
we need to apply break statement to terminate te while loop
👍
Thank you 😊
thanks
Pleasure 😊
if self.key is None:
print("Tree is empty")
return
if self.lchild:
node=self.lchild
while node.lchild :
node = node.lchild
print(node.key,"is the min number")
else:
print(self.key,"is the min key")
Is there any Trie structure video??