Saturday, February 3, 2018

Largest smaller binary search tree key

February 3, 2018

Introduction


It is 10:00 AM mock interview and I had to work on the algorithm called largest smaller binary search tree key.

Analysis of the algorithm


To search the key in the binary search tree, we do not have to traversal the whole tree, all we have to do is to start from root node and then go right or left, until meeting the dead end. For example, the node does not have left node but we have to check smaller value, or the node does not have right node but we have to check larger value. 

I made so many mistakes in past practices, and I remembered the time I was so nervous and then think about largest smaller, how to keep the largest one in the set of numbers. Since the value of smaller one is found, those numbers are in ascending order, only one variable is needed to keep current one. 


Code review 


Here is the C# code.


No comments:

Post a Comment