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

  • SEARCH
  • Home
  • 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 776383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:26:19+00:00 2026-05-14T19:26:19+00:00

This is a past exam paper on binary search trees I am attempting. I

  • 0

This is a past exam paper on binary search trees I am attempting. I have no way to check if the output is correct as I am not capable of building one of these things.

The question is in the title

class Tree{
    Tree left;
    Tree right;
    int key;

   public static int span(Tree tree)
   {
        if ( tree == null ){
             return null;
        }

        if( tree.left != null)
             int min = span(tree.left);
         }

        if( tree.right != null){
             int max = span(tree.right);
         }
         return max - min;
    }
}

Could anyone suggest what I need to change to get 5/5 marks 😀 – the only thing we have to do is write the span method, the header was given for us.

  • 1 1 Answer
  • 3 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-14T19:26:20+00:00Added an answer on May 14, 2026 at 7:26 pm

    You need to define two methods, min(Tree) and max(Tree), then span(Tree t) is defined as max(t) - min(t). span itself shouldn’t be recursive, but you can make min and max recursive if you want.

    Note that min and max doesn’t have to be their own methods. If you don’t care for making them stand as their own units, you can put it all into span like this:

    int span(Tree t) {
       Tree tMin = t;
       while (tMin.left != null) {
          tMin = tMin.left;
       }
    
       Tree tMax = t;
       while (tMax.right != null) {
          tMax = tMax.right;
       }
    
       return tMax.key - tMin.key;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the past, I have not really used namespaces, but in this project I
I did this in the past, and can't remember the correct command (I think
This is based on a past exam question. The question is asking to describe
I've got an exam coming up soon. I've been looking through the past paper,
This past summer I was developing a basic ASP.NET/SQL Server CRUD app, and unit
How do I get past this variable initialization problem? If I only could figure
I've looked for this a few times in the past, to no avail. I
In many past projects, I used this JPA / Hibernate approach to add auditing
I'll be the first to admit that this is cut and past programming. I've
I want to fix a file in past commit. This might affect all ascending

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.