• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 426
  • Last Modified:

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.
0
HLRosenberger
Asked:
HLRosenberger
1 Solution
 
GwynforWebCommented:
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now