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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:58:08+00:00 2026-05-30T08:58:08+00:00

I am hoping to get some input here. I have built a 2-dimenstional binary

  • 0

I am hoping to get some input here. I have built a 2-dimenstional binary search tree class. I have all operations (insert, delete etc.) working as they should. I have run into a problem that I can’t seem to get around. I currently have data members in each node, that must be updated within the deletion path (relative height, extrema values for respective sub-tree, etc). The problem is, I need my delete method to return a boolean value which represents it being successful. Meaning, if the node doesn’t exist, false is returned. Otherwise true.
I am solving this recursively, so when I come out of each function call, I am updating values

The get a basic idea of what is going on, here is what delete looks like:

private boolean delete (Node n, Value val, boolean cut) {
   // Base case
   if(n == null) return false;
   if(node to be deleted) {
        // Do all sorts of swapping, recursive deletion calls
   }
   else {
       // Move around the tree until I find a node or hit null
       if(is in left subtree)
         delete(t.left, val, !cut);
       if(is in right subtree)
         delete(t.right, val, !cut);
   }

   // Here is where updating happens
   someUpdateFunction(n);

   // Now java here is forcing me to return something, so I have to return true or false  
   return true;
}

So my problem is that I am always returning true, since this code always executes. Does anybody have any ideas of how I can update my deletion path, and still be able to return false if the node does not exist?
Thanks for any input.

  • 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-30T08:58:09+00:00Added an answer on May 30, 2026 at 8:58 am
    private boolean delete (Node n, Value val, boolean cut) {
       boolean status = false;
       // Base case
       if(n == null) return false;
       if(node to be deleted) {
            // Do all sorts of swapping, recursive deletion calls
       }
       else {
           // Move around the tree until I find a node or hit null
           if(is in left subtree){
                 status = delete(t.left, val, !cut);
           }else if(is in right subtree){
                 status = delete(t.right, val, !cut);
           }         
       }
    
       // Here is where updating happens
       someUpdateFunction(n);
    
       return status;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was hoping I could get some input on the best way to handle
I discovered something strange in gcc and hoping to get some input whether its
this is a bit of a newbie question but hoping I can get some
Hoping some learned Rails developers here can recommend an existing Ruby on Rails plugin
I'm a wee bit stuck on this, and was hoping you might have some
I've looked through some posts around here, but am still struggling to get my
Hey im working on my first php site, and was hoping to get some
I was hoping to get some opinions regarding best practices and comments on the
I have an interface that has ~16 input field boxes. They are all declared
I am hoping to find how I can get the kb size of a

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.