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 7560831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:00:18+00:00 2026-05-30T13:00:18+00:00

I am trying to write myself the isEmpty method for a binary tree but

  • 0

I am trying to write myself the isEmpty method for a binary tree but I am having a problem. So this is the method that I am using.

public boolean isEmpty(){
if(root == null) return true;
else return false;
}

When I add only one element, and then remove this element, and call isEmpty, I do not get true, but false.

Is there somethng wrong with my implementation?


So this is the remove method:

  /**
    * Internal method to remove from a subtree.
    * @param x the item to remove.
    * @param t the node that roots the tree.
    * @return the new root.
    * @throws ItemNotFoundException if x is not found.
    */
    protected BinaryNode<AnyType> remove( AnyType x, BinaryNode<AnyType> t )
    {
    if( t == null )
    throw new ItemNotFoundException( x.toString( ) );
    if( x.compareTo( t.element ) < 0 )
    t.left = remove( x, t.left );
    else if( x.compareTo( t.element ) > 0 )
    t.right = remove( x, t.right );
    else if( t.left != null && t.right != null ) // Two children
    {
    t.element = findMin( t.right ).element;
    t.right = removeMin( t.right );
    }
    else
    t = ( t.left != null ) ? t.left : t.right;
    return t;
    }

and this is the removeMin method that the remove method uses:

        /**
         * Internal method to remove minimum item from a subtree.
         * @param t the node that roots the tree.
         * @return the new root.
         * @throws ItemNotFoundException if t is empty.
         */
         protected BinaryNode<AnyType> removeMin( BinaryNode<AnyType> t )
         {
         if( t == null )
        throw new ItemNotFoundException( );
        else if( t.left != null )
        {
        t.left = removeMin( t.left );
        return t;
        }
        else
        return t.right;
        }
  • 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-30T13:00:19+00:00Added an answer on May 30, 2026 at 1:00 pm

    Check your remove element code. Usually than code find out parent of remove node and set to null corresponding reference. And for last element it have to set to null root variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I could probably write this myself, but the specific way I'm trying to accomplish
I've been trying myself, and searching online, to write this regular expression but without
Alright, so here's my problem. I'm trying to write a script in PHP that
I'm trying to write an unbreakable class using jQuery, so that: <span class=unbreakable> some
I'm trying to write myself a program that calculates a function taken from a
Context I'm trying to write myself a script that would toggle my WLAN adapter
I know it's been done before but I'm trying to write this from scratch
I'm trying to write a chat client using javascript, but I'm being hindered by
I'm trying to add a IsImage property that I wrote myself to the HttpPostedFile
Trying to write a PowerShell cmdlet that will mute the sound at start, unless

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.