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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:59:34+00:00 2026-06-05T01:59:34+00:00

From the original Mark Allen Weis RedBlackTree implementation from Data Structures and Problem Solving

  • 0

From the original Mark Allen Weis RedBlackTree implementation from Data Structures and Problem Solving Using Java found here.

I cannot seem to get my head around the removal of a node from the tree. After reading the wikipedia resource I noticed “is_leaf()” function.. the problem with this and Mark Weis implementation is there is no way to tell which node is a leaf and which isn’t

void delete_one_child(struct node *n)
{
    /*
     * Precondition: n has at most one non-null child.
     */
    struct node *child = is_leaf(n->right) ? n->left : n->right;

    replace_node(n, child);
    if (n->color == BLACK) {
            if (child->color == RED)
                    child->color = BLACK;
            else
                    delete_case1(child);
    }
    free(n);
}

Is_Leaf java implementation

public boolean isLeaf(){
if(left == null && right == null){
return false;
}
return true;
}

Console Output

value=1 color=1 leaf=true left=null right=14
value=2 color=1 leaf=true left=null right=5
value=5 color=0 leaf=true left=null right=null
value=7 color=0 leaf=true left=2 right=11
value=8 color=0 leaf=true left=null right=null
value=11 color=1 leaf=true left=8 right=null
value=14 color=1 leaf=true left=7 right=15
value=15 color=1 leaf=true left=null right=null

Tree format (From Console)

└── (1) 1
    └── (1) 14
        ├── (0) 7
        │   ├── (1) 2
        │   │   └── (0) 5
        │   └── (1) 11
        │       └── (0) 8
        └── (1) 15

Rules:

  1. The root is black
  2. Every red node has a black parent
  3. Any children of a red node are black
    – A red node cannot have red children
  4. Every path from the root to a leaf contains the same number
    of black nodes

So my question is how do I implement the removal from this implementation of Red and Back Trees?

  • 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-06-05T01:59:36+00:00Added an answer on June 5, 2026 at 1:59 am

    Are you asking how to implement isLeaf()? If so you should be passing isLeaf the node you want to check.

    public boolean isLeaf(RedBlackNode<AnyType> t ){
    if(t.left == null && t.right == null){
    return false;
    }
    return true;
    }
    

    Otherwise, the algorithm itself looks right, the only real work is translating C into Java which is easy.

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

Sidebar

Related Questions

FULL CLASS CODE HERE: http://pastebin.com/rdjDGLJS EDIT: Latest code snippet taken from original posters comment
I'm re-implementing a old BBS MUD game in Java with permission from the original
So I removed the /= requiretree line from the original application.css.scss but now I
When I do a git pull my repository automatically pulls from the original git
I want to create a Class, say MyDiv , which inherits from the original
Can I configure Varnish in such a way it shows the original page from
from this code will show in original color how can i change it to
Original issue Since I changed the version from 1.6.3. to 1.6.4 I get serious
I have stored images from the net like this Documents/imagecache/domain1/original/path/inURI/foo.png Documents/imagecache/domain2/original/path/inURI/bar.png Documents/imagecache/... Documents/imagecache/... Now
I would like to retrieve the original file name from a website while downloading

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.