• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Returning the largest value in a tree

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Saloon Keeper
Posts: 5178
207
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic