• Post Reply Bookmark Topic Watch Topic
  • New Topic

Returning the largest value in a tree  RSS feed

 
Aron Silvester
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write a new static method of the IntBTNode class to meet the following specification. Make the method as efficient as possible (do not visit nodes unnecessarily).

Does the code below meet the requirements?

public static int max(BTNode root)
// Precondition: root is the root reference of a nonempty binary SEARCH tree.
// Postcondition: The return value is the largest value in the tree.

 
Piet Souris
Master Rancher
Posts: 2042
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you think it meets the requirement? If so, why? If not, why not?

By the way: have you any idea why you need to know the root of a BST,
if you want to get the maximum value of that BST?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!