Python Program To Implement Binary Search Tree | Program 6 | Deletion | Example

  Рет қаралды 27,069

Amulya's Academy

Amulya's Academy

Күн бұрын

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 delete given node in tree.
#DataStructures #PythonPrograms #Tree
For more free tutorials on computer programming
/ amulsacademy
AmulsAcademy

Пікірлер: 90
@samridhshubham8109
@samridhshubham8109 Жыл бұрын
You know exactly which part we didn't get and then explain that part....sign of someone who themselves struggled to learn things... Absolutely amazing teacher👐!! Your playlist has helped me a lot, many many thanks for helping us out.
@AmandeepSingh-uq3wp
@AmandeepSingh-uq3wp 3 жыл бұрын
Thanks for making Data structures and algorithms lectures in python. Thanks A Lot!!! Please complete the whole DSA playlist.
@Arjunsingh-ne7lo
@Arjunsingh-ne7lo 3 жыл бұрын
thankyou mam best series ever, no one upload python datastructure but you have upload it. Thanks mam to building my basic concept remember forever
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Pleasure 😊
@Arjunsingh-ne7lo
@Arjunsingh-ne7lo 3 жыл бұрын
Mam please start few array problem series releted to interview ask
@rakshitharakshitha6912
@rakshitharakshitha6912 Жыл бұрын
One of the best explanation I've ever seen... Thanks so much Amulya... All the videos are really helpful. You explained each and every point..... thanks a million... Thanks from New York
@martinflavell3045
@martinflavell3045 Жыл бұрын
code on the left, example on the right = the best possible presentation/analysis. TYVM!
@PrinceKumar-tl2ut
@PrinceKumar-tl2ut 3 жыл бұрын
your explanation is superrrrr ❤ , you are way better than those paid data structure courses
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Haha… thank you 😊❤️
@peladixon
@peladixon 6 ай бұрын
you are the best teacher ever
@sivasrimakurthi206
@sivasrimakurthi206 Жыл бұрын
@amulya - I particularly like the step-by-step navigation of the code, to explain the logic line by line. this is great work. Keep it up!
@SnapSHORT1
@SnapSHORT1 3 жыл бұрын
I just wanna say one thing . this explanation is damn 🔥
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you 😊
@sonnetsandsmiles
@sonnetsandsmiles 3 жыл бұрын
thanks soooooooo much.. i was really confused before watching this this video.. i really thank uuu
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Pleasure 😊
@ashwinkumarramaswamy9369
@ashwinkumarramaswamy9369 3 жыл бұрын
Such a great explanation madam Awesome I just worried about last video how the deletion functionality comes in else part now its cleared!!!! Thank you so much ! 🤗
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
😊❤️
@KartikKothari-j1r
@KartikKothari-j1r 11 ай бұрын
Hi, your explanation is great. Thank you for putting so much effort and thanks again. I will complete and see your other tutorials too.
@demondeadpool331
@demondeadpool331 Жыл бұрын
i like the way you explain concepts like this and your voice too
@WeloveKoora
@WeloveKoora 2 жыл бұрын
thank you so much
@mantolbaloch4948
@mantolbaloch4948 2 жыл бұрын
Mam, your vedios have been very helpful to get the concept of Data structure 👍
@Anurag-kp6wc
@Anurag-kp6wc 3 жыл бұрын
Thanks a ton, Ma'am. You're the best.
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you 😊
@vachapatel9874
@vachapatel9874 3 жыл бұрын
best teaching ever ma'am!!! ❤❤❤
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you 😊❤️
@lohir446
@lohir446 2 жыл бұрын
Awesome work, really appreciate your effort on the content
@akshrags-mindmaze3407
@akshrags-mindmaze3407 Жыл бұрын
Nice explanation using diagram
@manthangandalwad4251
@manthangandalwad4251 3 жыл бұрын
Thank you for teaching us mam ..... Please upload remaining videos of data structure..
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Soon 😊
@aswath8265
@aswath8265 3 жыл бұрын
Great explanation 🔥🔥 amazing really shocked
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you 😊
@naveenchebolu6757
@naveenchebolu6757 3 жыл бұрын
Your videos are awesome after completion of data structures do the same for oops concepts also .
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Sure 😊
@johnsonabel5708
@johnsonabel5708 3 жыл бұрын
Good. I love this please can you do video on big O notation???
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you , will try 😊
@bhargav1811
@bhargav1811 3 жыл бұрын
Nice explaination !!!
@ujjwalshrivastava8368
@ujjwalshrivastava8368 2 жыл бұрын
Great fan mam😍😍😍
@settyruthvik6236
@settyruthvik6236 3 жыл бұрын
awesome explanation mam
@Futball860
@Futball860 2 жыл бұрын
This is so helpful. Thank you so much :)
@chiragbansal3228
@chiragbansal3228 3 жыл бұрын
Mam, please upload lectures on AVL Trees
@prashanthveddula9307
@prashanthveddula9307 3 жыл бұрын
Thanks a lot for this explanation !
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Pleasure 😊
@AmitYadav-vr3zx
@AmitYadav-vr3zx 3 жыл бұрын
awesome explaination 🔥
@ngocloile6641
@ngocloile6641 3 жыл бұрын
excellent explanation!, wish you do video about algorithm | Python, tks you!
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you 😊
@snr-u6h
@snr-u6h 3 жыл бұрын
thanks mam...keep completing DS.
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Sure 😊
@tareqoweinat5952
@tareqoweinat5952 2 жыл бұрын
awesome, thank you very much
@bikeshregmi946
@bikeshregmi946 3 жыл бұрын
Good Explanation!
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you 😊
@moulee007
@moulee007 2 жыл бұрын
can you please make a playlist on hashing , hash table is also a data structure right ?
@saranyav5244
@saranyav5244 3 жыл бұрын
Mam plz upload...software c c++ python install
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Noted 😊
@TechInShort
@TechInShort 3 жыл бұрын
Will you post Django tutorial or do you know any best tutorial for Django?
@zainabbohra2915
@zainabbohra2915 3 жыл бұрын
geekyshows
@idk____idk6530
@idk____idk6530 3 жыл бұрын
Mam can you make tutorial on TKINTER ...
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Will try 😊
@vijays-rd8uc
@vijays-rd8uc 3 жыл бұрын
Thank you
@rathnanaikrathnanaik
@rathnanaikrathnanaik 2 ай бұрын
nice mam
@shahrukh3531
@shahrukh3531 2 жыл бұрын
Is this approach standard or is it your personal approach to delete? I have made a program to find parent of node by searching first then delete it's child.
@sasivardhanbonthu8159
@sasivardhanbonthu8159 2 жыл бұрын
mam in last you returned" return self" what is meaning of that and what it will returns
@subhasis._khuntia
@subhasis._khuntia 3 жыл бұрын
in the else part why we are assigning self=None is it necessary to do this? is by skipping self=None affect the result?
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
I think you will get same answer 😊 Here to give you the feeling of deletion we used that 😊
@subhasis._khuntia
@subhasis._khuntia 3 жыл бұрын
@@AmulsAcademy thanks
@tridontridens5642
@tridontridens5642 3 жыл бұрын
How to make brute force?..plz create tutorial plz...
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Noted 😊
@selvanm2872
@selvanm2872 3 жыл бұрын
👍👍👍
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you 😊
@prachi7414
@prachi7414 3 жыл бұрын
Ma’am i so confused about the return self at last , how it is affecting the program i am not getting it!!! Please help me
@srikanthnethavath5807
@srikanthnethavath5807 2 жыл бұрын
Mam can I get pdf what you are explaining
@ishanmukherjee3962
@ishanmukherjee3962 3 жыл бұрын
Madam there are some problem in the code that need to be fixed. Hope you will find this comment helpful.
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Hey, getting any error? Please specify 😊
@cainsharma2104
@cainsharma2104 3 жыл бұрын
@@AmulsAcademy This particular delete function is deleting more keys than the one specified. This is deleting the root, the parent of the mentioned key and the key itself. root = BST(333) print("In Order Traversal") root.inorder() print("-----") myList = [20,30,40,1,2,6,15,17] for i in myList: root.insert_key(i) root.insert_key(1140) print("In Order Traversal") root.inorder() print("-----") root.search_key(17) root.search_key(20) print("Deleting Node 17") root.delete_key(17) #print("Pre Order Traversal") #root.preorder() print("-----") print("In Order Traversal") root.inorder()
@zainabbohra2915
@zainabbohra2915 3 жыл бұрын
mam what happen if we not write self, what self is doing , i am talking about return self in last line not getting that line.will you please explain , i also run on idle without using return self in last line. and its give me wrong result
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Hey in the next video I explained about that with example 😊
@zainabbohra2915
@zainabbohra2915 3 жыл бұрын
Always greatful ,Thank you so much mam💖💖
@aravindhan9183
@aravindhan9183 3 ай бұрын
this program wont work when the tree is like preorder--20 15 10 7 17 16 when we delete 15 from the tree
@priyanshushrimal5419
@priyanshushrimal5419 3 жыл бұрын
This method doesn't work when the root node has less than 2 children. Take a look at this code in addition to yours: def build_tree(elements): root = BST(elements[0]) for i in range(1, len(elements)): root.add_child(elements[i]) return root numbers = [15,20,222] number_list = build_tree(numbers) print(number_list.in_order_traversal()) number_list.delete(15) print("after deleting 15: ", number_list.in_order_traversal()) #15 doesn't get deleted.# Here's the full code incase you want it: #deleting a node class BinarySearchTreeNode: def __init__(self, data): self.data = data self.left = None self.right = None def add_child(self, data): if data == self.data: return elif data < self.data: #add data in left subtree if self.left: self.left.add_child(data) else: self.left = BinarySearchTreeNode(data) else: #add in right subtree if self.right: self.right.add_child(data) else: self.right = BinarySearchTreeNode(data) def in_order_traversal(self): elements = [] #visit left tree if self.left: elements += self.left.in_order_traversal() #visit base elements.append(self.data) #visit right tree if self.right: elements += self.right.in_order_traversal() return elements def search(self, value): if self.data == value: return True elif value < self.data: if self.left: return self.left.search(value) else: return False else: if self.right: return self.right.search(value) else: return False def find_min(self): if self.left: return self.left.find_min() else: return self.data def find_max(self): if self.right: return self.right.find_max() else: return self.data def delete(self, data): if self.data == None: print("Tree is empty") return if data < self.data: if self.left: self.left = self.left.delete(data) else: print("Not present") elif data > self.data: if self.right: self.right = self.right.delete(data) else: print("Not present") else: if self.left == None: temp = self.right self = None return temp if self.right is None: temp = self.left self = None return temp node = self.right while node.left: node = node.left self.data = node.data self.right = self.right.delete(node.data) return self def build_tree(elements): root = BinarySearchTreeNode(elements[0]) for i in range(1, len(elements)): root.add_child(elements[i]) return root numbers = [15,20,222] number_list = build_tree(numbers) print(number_list.in_order_traversal()) number_list.delete(15) print("after deleting 15: ", number_list.in_order_traversal())
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thanks for informing 😊 I will check that 😊
@vinaybandaru3994
@vinaybandaru3994 2 жыл бұрын
@@AmulsAcademy mam I got it, just equal the return value of delete function to the same object itself like... according to the code in the video numbers = [15,20,222] obj = BST(None) for i in numbers: obj.insert(i) obj = obj.delete(15) 👍👍
@manojkumarm9554
@manojkumarm9554 Жыл бұрын
I have a doubt! If 98 had two childs, 95 =left child and 110 = right child, now 95 will be the smallest in RST ,so now in place of 10(root) we should have (95) and after deleting smallest(95) in RST we will be returning none to the rchild of root ,since rchild of root is none the root will not have rchild so where is 98 and 110.
@manojkumarm9554
@manojkumarm9554 Жыл бұрын
Here i want to delete 10
@akshrags-mindmaze3407
@akshrags-mindmaze3407 Жыл бұрын
No. At 10:17 you can see, that if self.lchild is None, then only None will be returned, but in your case both lchild and rchild are not None(so both if statements will not execute) , so again node=self.rchild get executed and belew lines will execute , and as a result, the tree will be rearranged and finally last leaf node's rchild and lchild will only be set to None. Hope you understood!
@zainabbohra2915
@zainabbohra2915 3 жыл бұрын
mam why you made 76 and 77 video private?
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Really ? Let me check 😊 All videos are public, please mention the video name 😊
@zainabbohra2915
@zainabbohra2915 3 жыл бұрын
@@AmulsAcademy mam now it is showing 76 video is private and 77 is public but till yesterday it is showing both videos are private
@zainabbohra2915
@zainabbohra2915 3 жыл бұрын
@@AmulsAcademy sure mam
@iluminatibox9949
@iluminatibox9949 9 ай бұрын
WOWWWWWW!!!! you are the most well explained with details, I understand everysteps because of your explain . I would like if there is any possible chance you could make a vide explain this much detail in question 108 leetcode. I have a copy of Neetcode doing that question right here but his video was not clear so I can't understand much about how he got mid=1 so nums[1]=3. I would pay 40 CA for that vid through paypal!! I hope you can accept my request because I'm very weak as Tree and people on reddit and my teacher does not explain it clear enough for me. Thx here is his code: class Solution: def sortedArrayToBST(self, nums: List[int]) -> Optional[TreeNode]: def bst(l,r): if l>r: return mid=(l+r)//2 print(nums[mid]) nn=TreeNode(nums[mid]) nn.left=bst(l,mid-1) nn.right=bst(mid+1,r) return nn return bst(0,len(nums)-1) Thank you so much!!!!!!!
@a_36_rajdeep_ray12
@a_36_rajdeep_ray12 6 ай бұрын
Awesome explanation ❤
快乐总是短暂的!😂 #搞笑夫妻 #爱美食爱生活 #搞笑达人
00:14
朱大帅and依美姐
Рет қаралды 13 МЛН
FOREVER BUNNY
00:14
Natan por Aí
Рет қаралды 31 МЛН
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 6 МЛН
L44. Delete a Node in Binary Search Tree | BST | C++ | Java
15:48
take U forward
Рет қаралды 212 М.
Leetcode - Delete Node in a BST (Python)
8:30
Timothy H Chang
Рет қаралды 15 М.
5.10 Binary Search Trees (BST) - Insertion and Deletion | DSA Full Course
16:41
Jenny's Lectures CS IT
Рет қаралды 1,5 МЛН
Binary search tree - Implementation in C/C++
18:36
mycodeschool
Рет қаралды 1,3 МЛН
Delete a node from Binary Search Tree
18:27
mycodeschool
Рет қаралды 1,1 МЛН
Binary Search Tree in Python
22:59
NeuralNine
Рет қаралды 54 М.
10.1 AVL Tree - Insertion and Rotations
43:08
Abdul Bari
Рет қаралды 1,2 МЛН
Delete Node in a BST - Leetcode 450 - Python
12:59
NeetCodeIO
Рет қаралды 48 М.
快乐总是短暂的!😂 #搞笑夫妻 #爱美食爱生活 #搞笑达人
00:14
朱大帅and依美姐
Рет қаралды 13 МЛН