How do I implement a red-black tree in java. I am new to Java and have no clue how to proceed.
I need to be able to print out the tree as well.
Can someone help?!!

Recommended Answers

All 6 Replies

Well, if you know what a red-black tree is, you define a class for the nodes, a collection for those node, and the various methods to add, remove, search and print those node.

We can't simply do your homework for you. Post code and questions and someone can probably help.

I am not asking anyone to do my homework for me. I just need some help as I am new to Java. I understand the concept of Binary Trees and RB trees. I just don't know how to implement this in Java.
So my question is:
Will doubly linked lists be the best way to go about coding red-black trees? Or any other suggestions?
I am confused about whether it will be possible to form the tress structure with linked lists?

if you know how to create a tree you should know how to create one in Java.
There's nothing that makes Java different from say C++ in that.

And what exactly are you trying to do with a List when you want to make a Tree?

I'm sorry if I am not being clear. I do not know how to code a tree.
I understand what a Binary Tree and Red Black Tree is; but I have never coded either.
I understand that trees have nodes. How do I code these nodes? Are they the same nodes used to code a linked list??

Implementation of Red Black Trees in Java along with applet for illustration purposes.

you should make a class for nodes and a class with methods of insertion and deletion ,

if you can access CLRS book (introduction to algorithm) , you can find the code in chapter 13 : Red black trees

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.