Skip to content

Instantly share code, notes, and snippets.

Last active October 3, 2018 21:49
What would you like to do?
Find given node in a BST
// Find a node in the BST
static Node find(int val){
return find(root, val);
// Find a node in the BST recursive helper method
private static Node find(Node current, int val){
// return Null if BST does not contain given node
if(current == null) return null;
// return current node if matches given node
if( == val) return current;
// traverse the remain BST via node children
return > val ? find(current.left, val) : find(current.right, val);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment