I've studied a bit about recursion and I implemented what I learned on a binary search tree. I have a successful search and an unsuccessful search as my base case, and the algorithm function takes two parameters as input - one is the key that we are searching for in the binary search tree, and the other is the node that we are propagating the search from. The problem lies on formulating a pseudocode that answers the question.
I did the following approach - some said that it's wrong as I don't need the "@return" statement when I did the recursive call on either a node's left or right child but I argued that this is correct as we are expecting something out of that recursive function call and that if we remove the "@return" statement it will remove the recursive stack trace to the original caller of that function that begins the recursion and that node calling the search_bst(k, v) function will not have anything to return.
function search_bst(k, v):
if v.isExternal():
return v
if k = key(v):
return v
# search the left sub-tree
else if k < key(v):
return search(k, v.left)
# search the right sub-tree
else k > key(v):
return search(k, v.right)