Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6084131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:29:07+00:00 2026-05-23T11:29:07+00:00

I tried to answer the following 2 question, they are from a Java course

  • 0

I tried to answer the following 2 question, they are from a Java course test, but it is a little confusing because of the recursive that I’m probably need to use.

The first one is a method that receive a root of a binary tree and returns the maximum value on tree. (example in figure A).

This question (and the second) says only complete in the missing lines:

public static int maxInTree (Node root)
{
    if (root == null)
        return 0;
    if ((root.getLeftSon() == null) && (root.getRightSon() == null))
        ______________________    // I think that here: *return 1*;
    if (root.getLeftSon() == null)
    return _________________
    if (___________ == null)    // I think that here: *root.getRightSon()*
    _______________________________-
    return max______________________________
}

The second question says: do the same as the first question BUT for a sorted binary search tree.

public static int maxInSearchTree (Node r)
{
    if (r == null)
        return 0;
    if (r.getRightSon() == null)
        __________________________
    return _______________________________
}

You can assume there is a method to pullout the father: getNumber().

thnx !!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:29:08+00:00Added an answer on May 23, 2026 at 11:29 am

    I assume that getNumber() gives the value (not the father).

    public static int maxInTree (Node root)
    {
        if (root == null)
            return 0;
        if ((root.getLeftSon() == null) && (root.getRightSon() == null))
            return root.getNumber();
        if (root.getLeftSon() == null)
            return max(root.getNumber(), maxInTree(root.getRightSon()));
        if (root.getRightSon() == null)
            return max(root.getNumber(), maxInTree(root.getLeftSon()));
        return max(root.getNumber(),
            max(maxInTree(root.getLeftSon()),maxInTree(root.getRightSon())));
    }
    
    public static int maxInSearchTree (Node r)
    {
        if (r == null)
            return 0;
        if (r.getRightSon() == null)
            return r.getNumber();
        return maxInSearchTree(r.getRightSon());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried following the answer to this question , but could not get xsd.exe
In interview I have been asked following question. I tried to answer the question
I posted the following question yesterday but didn't get a helpful answer. May i
I tried googling the answer, but all I found was tips on how to
tried to find the answer by googling and in MSDN but with no luck.
I've tried to find an answer to do this online but apparently it can't
Ok, I have tried searching around for this answer, but with no luck. I
Ok, this probably has a really simple answer, but I've never tried to do
Tried to map it from Preferences -> Settings -> Keyboard, but the key combo
I tried to do some research on this and came across the following question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.