largest key in a binary search tree

To find the largest key in a binary search tree, is this correct:  start at the root, and recursively visit the node.  When the right child is null, the node contains the largest key.
LVL 1
HLRosenbergerAsked:
Who is Participating?
 
GwynforWebConnect With a Mentor Commented:
That is correct, ie always go right as everything to the left will be smaller. Until there is  no right child to visit.

 In pseudo code it becomes


function findLargest(node){
  if (node.rightChild == null) return node.value
  return findLargest(node.rightChild)
}

findLargest(root)
0
 
HLRosenbergerAuthor Commented:
Thank You
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.