bsc

Comprehensive codebase and coursework for the 4-year B.Sc. Computer Science Honours degree (WBSU)

git clone https://github.com/notamitgamer/bsc.git
· rebuilt hourlyOpen on GitHub
root / semester_2 / algorithms / algo_058.md

algo_058.md (412B)


      1 # algo_058
      2 
      3 ### Problem Statement
      4 
      5 > Write a non-recursive algorithm to search an element in a Binary Search Tree (BST).
      6 
      7 ## Algorithm
      8 ```
      9 procedure search(T, key)
     10 begin
     11     while (T ≠ NULL) do
     12         if (INFO(T) = key) then
     13             return T;
     14         else if (key < INFO(T)) then
     15             T ← LC(T);
     16         else
     17             T ← RC(T);
     18         endif
     19     endwhile
     20     return NULL;
     21 end procedure
     22 ```