bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_2 / algorithms / algo_062.md

algo_062.md (796B)


      1 # algo_062
      2 
      3 ### Problem Statement
      4 
      5 > Write an algorithm to delete a node from a Binary Search Tree (BST).
      6 
      7 ## Algorithm
      8 ```
      9 procedure deleteNode(root, key)
     10 begin
     11     if (root = NULL) then
     12         return root;
     13     else if (key < INFO(root)) then
     14         LC(root) ← deleteNode(LC(root), key);
     15     else if (key > INFO(root)) then
     16         RC(root) ← deleteNode(RC(root), key);
     17     else
     18         if (LC(root) = NULL) then
     19             temp ← RC(root);
     20             free(root);
     21             return temp;
     22         else if (RC(root) = NULL) then
     23             temp ← LC(root);
     24             free(root);
     25             return temp;
     26         endif
     27         temp ← ins(root);
     28         INFO(root) ← INFO(temp);
     29         RC(root) ← deleteNode(RC(root), INFO(temp));
     30     endif
     31     return root;
     32 end procedure
     33 ```
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror