Delete a Node in BST | Deletion in BST | Delete a Node in Binary Search Tree | DSA-One Course #68

Sdílet
Vložit
  • čas přidán 31. 01. 2022
  • Hey guys, In this video, We're going to learn how to delete a Node in a Binary Search Tree.
    Practice here: practice.geeksforgeeks.org/pr...
    💸 Use coupon code ANUJBHAIYA on GeeksforGeeks to avail discounts on courses!
    🥳 Join our Telegram Community:
    Telegram channel: telegram.me/realanujbhaiya
    Telegram group: telegram.me/dsa_one
    🚀 Follow me on:
    Instagram: / anuj.kumar.sharma
    Linkedin: / sharma-kumar-anuj
    Twitter: / realanujbhaiya
    📚 Complete DSA Playlist: • DSA-One Course - The C...
    Complete Android Development Playlist: • Android Development Tu...
    Hashtags:
    #anujbhaiya #dsaone
    Tags:
    delete node in bst
    delete a node in bst
    anuj bhaiya
    deletion in bst
    delete node in a bst
    bst
    deletion in binary search tree
    delete a node from bst
    bst deletion
    delete in bst
    binary search tree deletion
    binary search tree
    delete node from bst
    binary search tree in data structure
    450. delete node in a bst
    binary search tree in java
    delete node bst
    insertion in binary search tree
    bst delete
    deletion in binary tree
    dsa
    anuj bhaiya dsa
    anuj bhaiya java
    delete a node in binary search tree
    delete node in binary search tree
    deleting a node in bst
    evaluate boolean binary tree
    anuj bhai
    binary search in java
    binary search tree c++
    binary search tree delete
    binary search tree insertion
    binary search tree javascript
    binary tree deletion
    binary tree to bst
    delete in binary search tree
    tree dsa
    aasman ko chukar dekha
    anuj kumar sharma
    binary search in c
    binary search tree implementation
    binary search tree in c
    binary search trees
    binary tree in data structure
    binary tree java
    bst in dsa
    bst insertion
    bst insertion and deletion
    bst java
    bst tree
    data structures and algorithms
    deletion of a node in bst
    deletion of node in bst
    dijkstra algorithm
    dsa trees
    geeksforgeeks
    inorder predecessor and successor in bst
    insertion and deletion in bst
    insertion in binary tree
    java by anuj bhaiya
    lead coding
    leetcode 450
    level order traversal binary tree
    search in bst
    searching in binary search tree
    tree
    tree data structure in java
    trees

Komentáře • 58

  • @startupmindset7597
    @startupmindset7597 Před rokem +12

    my all friends learn things from different coaching classes in hydrabad ,Mumbai or pune ....but they have not much knowledge in programming , but i learn from anuj bhaiya DSA one course which is free and i have so much knowledge , compare to my friends , they always call me to ask the doubts, ...
    thank you ANUJ BHAIYA for this great course .....free for us.....

    • @girlysh09
      @girlysh09 Před 10 měsíci +1

      then suggest them this playlist dude

  • @digvijay17july
    @digvijay17july Před 2 lety +13

    Finally, one of the awaited videos For BST Lovers 🤣

  • @trishnapatil4594
    @trishnapatil4594 Před rokem +4

    What a wonderful explanation to an otherwise complex problem! Loved it! Thanks a lot!

  • @areversemotivation7657
    @areversemotivation7657 Před rokem +1

    was stuck on this from long time but after watching this video, the concept is crystal clear

  • @shinratenten5686
    @shinratenten5686 Před rokem

    experienced it many times, you make every concept easier

  • @raunakrhishabh2773
    @raunakrhishabh2773 Před rokem

    The way u explain & made things visualize, its awsm!!! Thnx bro

  • @user-lg9sj3yw9l
    @user-lg9sj3yw9l Před 8 měsíci +1

    sir program ko pura show kiya kre #include se end tk...plz...otherwise samjhne me dikkt aati h

  • @AK-ft7fd
    @AK-ft7fd Před rokem +2

    This solution in leetcode shows RUNTIME ERROR. Please help!

  • @tushargogiya4017
    @tushargogiya4017 Před 2 lety +1

    Nice Explanation bhaiya hats off to you

  • @user-lg9sj3yw9l
    @user-lg9sj3yw9l Před 8 měsíci +1

    sir jo program ko aap smjhate ho usko bhi description me dal de to or bhi benefitial ho...smjhne mei

  • @jatindigra4329
    @jatindigra4329 Před rokem

    awesome !! loved the explanation !!

  • @kartikeyrawat5456
    @kartikeyrawat5456 Před 5 měsíci

    Very nice explanation !!! God bless you.

  • @zakyvids6566
    @zakyvids6566 Před 2 lety +3

    Hi Anuj Bhaiya I like your content a lot
    But I had a request please make oops in python as well as how to use pyautogui and selenium
    Thanks a lot
    Love from Australia ❤️❤️❤️❤️❤️👍👍👍👍👍

  • @meenakshidwivedi83
    @meenakshidwivedi83 Před 2 lety

    Truely Awesome..Thanks

  • @pallavigavali2671
    @pallavigavali2671 Před 2 lety +2

    Thank you bhaiya 👍

  • @SaiKiranPatro
    @SaiKiranPatro Před 4 měsíci

    No one can better explain than Anuj Bhaiya ❤

  • @rahulsinghshekhawat2487

    great explanation !!!

  • @parasdua4242
    @parasdua4242 Před rokem +1

    So, smooooooth
    Amazing ✨

  • @stith_pragya
    @stith_pragya Před 7 měsíci

    Thank You So Much for this wonderful video........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @girishmahajan4130
    @girishmahajan4130 Před 2 lety

    Thank you so much bhaiya

  • @pt_harshit
    @pt_harshit Před 2 lety +2

    Nice...

  • @coftanurag
    @coftanurag Před 11 měsíci +1

    I think you miss leaf node deletion case

  • @user-yv8eo8cl3y
    @user-yv8eo8cl3y Před měsícem

    many times better than apna college not spreading hate but its fact 100%

  • @dhanrajlouvanshi7872
    @dhanrajlouvanshi7872 Před 2 lety

    Thanks

  • @abhinavsinha8116
    @abhinavsinha8116 Před 2 lety +5

    Sir, I need your java placement cousre playlist which got deleted. There very important lectures in that playlist. Please do somethng.

  • @saritaprasad4295
    @saritaprasad4295 Před rokem

    tough topic explanation in easy way

  • @pratimdutta1979
    @pratimdutta1979 Před 7 měsíci

    thank you sir

  • @lokendrasingh9780
    @lokendrasingh9780 Před 2 lety +1

    Bhaiya whiteboard is best 👍❤️
    thank you bhaiya ❤️❤️

  • @musqitonebeats2129
    @musqitonebeats2129 Před rokem +1

    time complexity?

  • @NishantKumar-bu7wh
    @NishantKumar-bu7wh Před 3 měsíci

    Can anyone please explain that if the root of updated subtree is already attached to the root of the BST, why is it explicitly compulsory to attach again to the root of the BST?

  • @gtbaba123
    @gtbaba123 Před rokem

    Bro I love u

  • @anshulsingh1265
    @anshulsingh1265 Před 2 lety +1

    Done

  • @codingiseasy8
    @codingiseasy8 Před rokem

    Nic sir

  • @rudrakshdatta4389
    @rudrakshdatta4389 Před 2 lety +1

    Share the code of delete and insert node in a Binary Search Tree

  • @chandraveersingh5561
    @chandraveersingh5561 Před 2 lety +13

    Hi Bhaiya! Mera comment pin krdo Mai dosto ko dikhao ga

  • @MACR_RaviKumar
    @MACR_RaviKumar Před 2 lety +1

    ❤❤

  • @sankalpgupta5505
    @sankalpgupta5505 Před 2 lety +4

    bhaiya are you going to cover graphs and DP as well???

    • @anujkumarsharma1013
      @anujkumarsharma1013 Před 2 lety +2

      Yes, these topics will come after.

    • @babunmadhab
      @babunmadhab Před 2 lety

      @@anujkumarsharma1013 bhaiya code thoda link description m de dijiye na

  • @sankalpgupta5505
    @sankalpgupta5505 Před 2 lety +7

    bhaiya please make a roadmap on international placements🙏❤️

  • @premprakashsahu7923
    @premprakashsahu7923 Před 2 lety +2

    Bhaiya thodi jldi jldi videos bnaya kro ,reach ni bdh ri

  • @creativevision9204
    @creativevision9204 Před 2 lety +1

    Please share iterative approach as well.

  • @deepakantoj432
    @deepakantoj432 Před rokem

    the question is to delete a node from BST
    my approach is that i'll first get the key node
    and then also get the parent node of the key node .
    connect the parent node's left or right to key node's right .
    and store the key node's left in a temp node
    i'll traverse to the very left of the newly connected parent's left and attach the temp .
    /**
    * Definition for a binary tree node.
    * public class TreeNode {
    * int val;
    * TreeNode left;
    * TreeNode right;
    * TreeNode() {}
    * TreeNode(int val) { this.val = val; }
    * TreeNode(int val, TreeNode left, TreeNode right) {
    * this.val = val;
    * this.left = left;
    * this.right = right;
    * }
    * }
    */
    class Solution {
    public TreeNode deleteNode(TreeNode root, int key) {
    TreeNode node = solve(root,key); // key node
    TreeNode n = helper(root,key); // parent node
    if(n.left != null)
    if( n.left.val == key)
    n.left = node.right;
    else if(n.right != null)
    if(n.right.val == key)
    n.right = node.right;
    TreeNode left = node.left;
    TreeNode cur = node.right;
    while(cur.left!=null)
    {
    cur = cur.left;
    }
    cur.left = left;
    return root;
    }
    public TreeNode helper(TreeNode root , int val)
    {
    if(root == null)
    return null;
    if(root.left!=null)
    {
    if(val == root.left.val)
    return root;
    }
    else if(root.right!=null){
    if(val == root.right.val)
    return root;
    }
    return val > root.val ? helper(root.right , val) : helper(root.left , val);
    }
    public TreeNode solve(TreeNode root , int val)
    {
    if(root == null)
    return null;
    if(val == root.val)
    return root;
    return val > root.val ? solve(root.right , val) : solve(root.left , val);
    }
    }
    where have i gone wrong anybody please help

  • @Coding_Destini
    @Coding_Destini Před rokem

    Bhaiiyya but where we are checking when key (data to be delete) == root.data ????

  • @codingwithsukesh
    @codingwithsukesh Před 10 měsíci

    💖💖👍👍

  • @pandeyshashidhar
    @pandeyshashidhar Před rokem

    In leetcode code is showing TLE
    class Solution {
    public TreeNode deleteNode(TreeNode root, int key) {
    if(root == null) return null;
    if(key < root.val) root.left = deleteNode(root.left,key);
    else if(key>root.val) root.right = deleteNode(root.right,key);
    else{
    if(root.left == null) return root.right;
    else if(root.right == null) return root.left;
    root.val = maxElement(root.right);
    root.right = deleteNode(root.right,root.val);
    }
    return root;
    }
    public int maxElement(TreeNode root){
    while(root.left != null){
    root.val = root.left.val;
    }
    return root.val;
    }
    }

    • @praminthakur8166
      @praminthakur8166 Před rokem

      In the maxElement() method , you are not setting a condition for the while loop to end. Thus, it will give TLE.
      It should be :
      public int minElement(TreeNode root){
      int minv = root.val;
      while(root != null){
      if(root.val < minv) minv = root.val;
      root = root.left;
      }
      return minv;
      }

    • @NayeemKhan-gg2nc
      @NayeemKhan-gg2nc Před 6 měsíci

      in your maxElement function inside while loop you have to add root = root.left;

  • @user-np9iw1qf8g
    @user-np9iw1qf8g Před 4 měsíci

    He talks very quickly 😅

  • @user-em1mz8hz4e
    @user-em1mz8hz4e Před rokem

    Thanks