Binary Search Tree Deletion | Data Structure | Bangla Tutorial

Поділитися
Вставка
  • Опубліковано 17 жов 2024

КОМЕНТАРІ • 20

  • @nafiulislamraj294
    @nafiulislamraj294 Рік тому +3

    Correction:- Example 2 te right sub tree er minimum value 9.

  • @MazidulIslam-n2o
    @MazidulIslam-n2o 11 днів тому

    The process of deleting 6 is wrong . This node has only one children. So we can delete it replacing 4 here. Waiting for your reply,sir.

  • @rhsiam9275
    @rhsiam9275 2 роки тому +1

    Nice bro... I am see your full data structure playlist

  • @ItzRZ77
    @ItzRZ77 Рік тому

    Vai example 1 e 10 delete korte 15 o toh root e nite partam taina?

  • @safayetullah8571
    @safayetullah8571 5 місяців тому

    nice explain in short..

  • @ashrafahmedsizan9883
    @ashrafahmedsizan9883 2 роки тому

    you are the best,make videoes on assembly language

  • @ammarbinqasem10
    @ammarbinqasem10 4 місяці тому

    Perfect explain

  • @ReduanAhmadRasel
    @ReduanAhmadRasel 3 місяці тому

    Example 2 te right sub tree er minimum value 9.

  • @shuvovai1298
    @shuvovai1298 2 роки тому

    That's great vai❣️

  • @animeking8713
    @animeking8713 10 місяців тому

    Usefull❤

  • @wahidadmmc5741
    @wahidadmmc5741 4 роки тому +1

    you are doing great

  • @blackmen8842
    @blackmen8842 Рік тому

    code likhe bujhale helpful hoto

  • @passionatequeen
    @passionatequeen 2 роки тому

    Thanks

  • @md.marufsarker
    @md.marufsarker Рік тому

    Last example solution is wrong. We need minimum and here 10 is the minimum value not 12

  • @onto7104
    @onto7104 2 місяці тому

    /* Deleting a node from Binary search tree */
    #include
    using namespace std;
    struct Node {
    int data;
    struct Node *left;
    struct Node *right;
    };
    //Function to find minimum in a tree.
    Node* FindMin(Node* root)
    {
    while(root->left != NULL) root = root->left;
    return root;
    }
    // Function to search a delete a value from tree.
    struct Node* Delete(struct Node *root, int data) {
    if(root == NULL) return root;
    else if(data < root->data) root->left = Delete(root->left,data);
    else if (data > root->data) root->right = Delete(root->right,data);
    // Wohoo... I found you, Get ready to be deleted
    else {
    // Case 1: No child
    if(root->left == NULL && root->right == NULL) {
    delete root;
    root = NULL;
    }
    //Case 2: One child
    else if(root->left == NULL) {
    struct Node *temp = root;
    root = root->right;
    delete temp;
    }
    else if(root->right == NULL) {
    struct Node *temp = root;
    root = root->left;
    delete temp;
    }
    // case 3: 2 children
    else {
    struct Node *temp = FindMin(root->right);
    root->data = temp->data;
    root->right = Delete(root->right,temp->data);
    }
    }
    return root;
    }
    //Function to visit nodes in Inorder
    void Inorder(Node *root) {
    if(root == NULL) return;
    Inorder(root->left); //Visit left subtree
    printf("%d ",root->data); //Print data
    Inorder(root->right); // Visit right subtree
    }
    // Function to Insert Node in a Binary Search Tree
    Node* Insert(Node *root,char data) {
    if(root == NULL) {
    root = new Node();
    root->data = data;
    root->left = root->right = NULL;
    }
    else if(data data)
    root->left = Insert(root->left,data);
    else
    root->right = Insert(root->right,data);
    return root;
    }
    int main() {
    /*Code To Test the logic
    Creating an example tree
    5
    / \
    3 10
    / \ \
    1 4 11
    */
    Node* root = NULL;
    root = Insert(root,5); root = Insert(root,10);
    root = Insert(root,3); root = Insert(root,4);
    root = Insert(root,1); root = Insert(root,11);
    // Deleting node with value 5, change this value to test other cases
    root = Delete(root,5);
    //Print Nodes in Inorder
    coutright);
    root->data = temp->data;
    root->right = Delete(root->right,temp->data);

  • @sharourjahan8914
    @sharourjahan8914 3 роки тому

    Thanks