Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exisiting Tree Library in Java? [duplicate]

Tags:

java

I am trying to create a Tree like structure were i have a root node and then i can add childrens to the root node and continue the process. I am not really interested in sorting. All i want is a tree like structure since i am creating an Org Chart.

Is there an exisitng java library that will let me add root node, child node or for example get a child node from a tree and then add child to those nodes as well. Or maybe get all the leaf node from a tree.

I am trying to avoid creating one on my own just to save time ? Any libraries you can suggest will be of great help .

Note: I am not using Swing or AWT components.

like image 526
user3398326 Avatar asked Apr 11 '14 12:04

user3398326


People also ask

Can tree contain duplicates?

In a Binary Search Tree (BST), all keys in left subtree of a key must be smaller and all keys in right subtree must be greater. So a Binary Search Tree by definition has distinct keys.

Are duplicates allowed in binary tree?

For a node, x, with key, k, every key in x's left subtree is less than or equal to k, and every key in x's right subtree is greater than or equal to k. Note that the definition permits duplicate keys. Some BSTs don't permit duplicate keys. Whether to permit duplicate keys depends upon the application that uses the BST.

How do I find the duplicate subtree of a tree?

For each duplicate subtree, we only need to return the root node of any one of them. Two trees are duplicates if they have the same structure with the same node values. Examples: Input : 1 / \ 2 3 / / \ 4 2 4 / 4 Output : 2 / and 4 4 Explanation: Above Trees are two duplicate subtrees.

Can Red Black tree have duplicates?

Sure, a binary search tree can have duplicates, if you allow them. For example C++ has both std::set and std::multiset . These two containers are almost identical. Both are typically implemented as red-black trees, which are balanced binary search trees.


1 Answers

The TreeModel interface in Java is designed for this. DefaultTreeModel supports adding any number of children to a node, listening on a node, and looking up nodes by path.

like image 121
Russell Zahniser Avatar answered Sep 28 '22 17:09

Russell Zahniser