Trees Data Structures in Java

Hi all !
Currently I�m developing a Java software that requires a Tree data structure. Searching through Java API I�ve found classes like TreeMap and TreeSet, but although these classes seens to use tree structure behind what they really provide are linear data structure, not a tree data structure. My question is if there is a public and free Java tree data structure that permits to do activities such as:
- Search for a particular node (efficiently)
- Insert children to any node
- Maintain one Object in each node
Simple like this ! It must have something like this in Java, but I just can�t find it and I�m just too lazy to implement it :) ! Anyone can help me ?
Thanks in advance !

Mel,
I�ve seen javax.swing.tree.TreeModel and its seens more like an implementation of Control in swing MVC (Model Vision Control) swing paradigm for JTree. It has listeners generated for manipulation events for example. It uses javax.swing.tree.DefaultMutableTreeNode for its nodes, and maybe I could use this class for the nodes of my tree since it has many useful operations. However still I miss a node searching operation that this class doesn�t have.
Yes my problem is a simple Tree, but it is simple now and it might become much more complex, demanding more operations on the tree and specially efficient searching algorithms. Thats why I�m looking for a complete solution and I prefer something that is already done and well tested :) !
Thanks for your tip !

Similar Messages

  • What Tree Data Structures does Java Include?

    Hello,
    I have been reading about several tree data structures like a binary search tree, self-balancing bst, minimum spanning tree, red-black tree, AVL tree, etc... Are there data structures in Java represent the various trees, or is implementation of the ds left to user?
    Eric

    "Java" can be termed the "Java Language". The language does not have trees.
    In more general usage "Java" can refer to a standard, desktop, delivered VM which includes the standard Java API. The types that you are asking about would be found in the following package.
    [http://java.sun.com/javase/6/docs/api/java/util/package-summary.html]
    "Java" could also refer to any other commonly available implementations. In that case probably anything that can be implemented has been implemented somewhere. Googling works.

  • 3750x Stack UTIL-3-TREE: Data structure error--attempt to remove an unthreaded node from a tree

    A Cisco Stack 3750X switch report the following error message:
    %UTIL-3-TREE: Data structure error--attempt to remove an unthreaded node from a tree.
    every minute +-20 sec
    Cisco IOS Software, C3750E Software (C3750E-IPBASEK9-M), Version 15.0(2)SE4, RELEASE SOFTWARE (fc1)
    analog bug: https://tools.cisco.com/bugsearch/bug/CSCsz93221

    WS-C3750G-24PS-E C3750-IPBASEK9-M version 12.2(53)SE2
    After implementing 802.1x with Avaya IP phones
    %UTIL-3-TREE: Data structure error--attempt to remove an unthreaded node from a tree
    Port then fails authentication and goes into vl-err-dis

  • Is there a Java API for Tree data structure?

    Hi,
    I am wondering is there any Java API to work on Tree based data structure.
    I could read in some forums / sites that teach me how to create tree based objects using collection.
    But I wanted to know is there any core java API that can be used directly for tree based operations. (like binary tree or other type of trees)
    Please comment on this doubt.

    Headed using google and other stuff not found one.
    Suggestion: Why not start building the one, its a good idea to do that, isn't it.

  • Tree   Data  Structure

    Hello Guys,
    I am stuck in my project for a while and decided to contact you guys for ideas because am short of ideas how to get it done. This is the task: I have information like this from the server and have to create a tree structure from the information(data). The data from the server comes in this form:
    APP               net       main
    Account        net      main
    Address        net      main
    Person        net      OptelClient3
    Person        net      ggggg
    Person        net      show
    Bindings    apple    parse
    Bindings    apple    findProject
    Bindings    apple    show
    The positions of the columns is not fixed. The first column can become the second or the third depending on the preference of the user.
    1)
    The task is this:
    In each row , the first data must be the parent of the second data, the second data must be the parent of the third data and if there appears to be a fourth data then it will be the child of the third and it follows like that......
    I have to be able to build this tree structure whiles am looping over the information from the server.
    *****Optional Requirement****
    And if it is possible i must also be able to use the structure to create a table.
    I have spent much time(weeks after weeks) doing it but its not working so am asking if someone can help me with ideas how to get this done or point me to a tutorial where i can have a deep understanding of how i can do it.
    Thank for your help.

    Thanks for your reply.
    I have to implement the tree from the list i receive from the server. Each column belongs to the same class. For instance the first column will belong to a class called say "cHuman" and i will set the name attribute of each class to the names of the first column.
    The second coulumn will belong to the same class say "cPackage"and i will set each to the names of the second column datas. This apply to the rest of the columns.
    What am asking is simple. How can i build the tree dynamically so that the in each row, every data is parent to the next data. That is all what i want. What am doing is correct but i just need how to create the tree dynamically. Show me how to build trees dynamically from data.
    Thanks.

  • Trie data structure using Java

    No need to see the code...
    i properly documented for easy understanding....
    plz dont hesistate to go through code..
    class treenode{                //tree node structre....
       char ch;
       treenode child;
       treenode sibling;
        treenode(){                              //constructore
            child=null;
            sibling=null;
            ch='$';
    public class trie{
       treenode root=new node();             //defining root node
       public void main(String s{}){
             string s1[]={"hi","subbu","how r u"};
            for(int i=0;i<s1.lengh();i++){
                        storetrie(s1,root.sibling); //calling trie function
    printtrie(temp.sibling);
    printtrie(treenode temp){                             //printing trie
    if(temp!=null){
    System.out.print(temp.ch);
    printtrie(temp.child):
    printtrie(temp.sibling);
    public void storetrie(String str,treenode temp){       //constructing trie
    if(temp==null){             // if data is dissimilar
    int i=0,k=str.length(); //storing string length
    temp=new treenode();
    while(i<k){                 //add string to trie one charater by character
    temp.ch=str.charAt(0);
    str=str.substring(1); //forwarding string
    System.out.print(temp.ch);
    temp.sibling=null;
    temp.child=new treenode(); //for next child
    temp=temp.child; //moving to child
    i++;
    if(root.sibling==null){                  //errorrrrrrrrrrrrr        this condition should fail......but it is satisfying...........objects are passed through refences...it should change i think...
    System.out.println("root is null..");
    else{
    if(str.charAt(0)==temp.ch){
    storetrie(str.substring(1),temp.child);
    else{
    storetrie(str,temp.sibling);

    this is my actual code...
    this code will take some folder address on hard disk
    filenames stored in folders iam storing in trie
    trie is not printing...
    my code is not storing filenames in trie ...what could be the problem
    import java.io.*;
    import java.io.File;
    class treenode{
          char ch;
          treenode sibling;
          treenode child;
          public treenode(){
               sibling=null;
               child=null;
               ch='$';
    public class finalone{
           treenode root=new treenode();       //root node definition
           public static void main(String s[]){
                  finalone x=new finalone();
                  File f=new File("G:/Papers");      //folder address
                  x.store(f);
                  System.out.println();
                  x.printtrie1();                              //calling printing trie function
            public void printtrie1(){
               printtrie(root.sibling);
            public void store(File f){
                   if(f.isDirectory()){
                          File str[]=f.listFiles();
                          String strname[]=f.list();
                          for(int i=0;i<str.length;i++){
                                storetrie(strname,root.sibling);
    if(i==0)break;
    // System.out.println(strname[i]);
    // store(str[i]);
    else{
    // System.out.println(f);
    public void printtrie(treenode temp){
    if(temp!=null){
    System.out.print(temp.ch);
    printtrie(temp.child);
    System.out.println();
    printtrie(temp.sibling);
    public void storetrie(String str,treenode temp){
    if(temp==null){
    int i=0,k=str.length();
    temp=new treenode();
    while(i<k){
    if(str==null){
    return;
    temp.ch=str.charAt(0);
    str=str.substring(1);
    System.out.print(temp.ch);
    temp.sibling=null;
    temp.child=new treenode();
    temp=temp.child;
    i++;
    //temp=null;
    if(root.sibling==null){
    System.out.println("root is null..");
    else{
    if(str.charAt(0)==temp.ch){
    storetrie(str.substring(1),temp.child);
    else{
    storetrie(str,temp.sibling);

  • Need help in Data Structure in Java

    Design a FSA which accepts all strings over {a,b} which end in b, and in which every b (except for the last one) is immediately followed by two or more a's.
    Convert the following into a deterministic finite state automaton, using the subset construction algorithm.
    a,b
    \/ a b a
    --> 0 --> 1 --> 2 ---> 3
    State 3 is accepting.
    Describe (in English) the language which the regular expression (a|ba)* denotes.
    Using the techniques discussed in class, convert the regular expression in the previous problem to an FSA with epsilon transitions.
    Now convert the FSA from the previous problem to an equivalent FSA without epsilon transitions.
    I have to solve this problem .. can anyone help me out here?

    I have to solve this problem .. can anyone help me out
    here?Your code didn't show up in the post. Please re-post with code
    describing where you are having the problem.

  • Data Structures and Algorithms in java book

    Hi guys,
    I want to know a good book which is good for Data Structures and Algorithms in java. I am good at Core java but a beginner for Data Structures in Java. I am a little poor in Data Structures concepts.
    Following are the books I have found on the net. Could you help me the choose the best outta them.
    1. Data Structures and Algorithms in Java - Mitchell Waite
    2. Data Structures in Java - Sandra Anderson
    3. Fundamentals of OOP and Data Structures in Java - Richard Weiner & Lewis J. Pinson
    4. Object Oriented Data Structures Using Java - Nell Dale, Daniel T. Joyce, Chip Weems

    lieni wrote:
    I good data structures book doesn't have to be language-specific.Thx DrLazlo, my speachYes.
    The OP wrote:
    I have access to these books and dont know which one to start with.What I meant is that you shouldn't narrow your search to insist that the book you choose have "Java" in the title.

  • Need a good Data Structure/ Algorithm

    I am working on a small problem that requires me to cache a large amount of key/value pairs of data. I must then do a lookup on the cache for a large number of words one after another until I find a word that is present as a Key and then quit.
    The cache is pretty large. About 600 - 1000 words as keys and ints as values.
    Is there an existing Data Structure in Java for this? If not, what type of data structure (B-tree etc) is best suited to cache such data and what algorithm should be used for lookup?

    The lookup for hashmap is efficient for very large maps up to the amount of memory you have. If you tune the load factor you can minimise the impact of having very large tables.
    Another option is to have a fixed array of HashMaps. You can use the hashcode (or your own) to put the key, value into the HashMap. I am not sure if this is actaully any faster, as I believe one is enough, but if you have concern this is what you can do.

  • Data structure for simulation of message queue

    Hello,
    I have undertaken a project of simulating the point to point and publish/subscribe protocols of message queueing. This whole project would be done just in Java. There won't be any system level programming. Which data structure in Java would be the most efficient one for the message queue?

    Hello,
    I have undertaken a project of simulating the point to point and publish/subscribe protocols of message queueing. This whole project would be done just in Java. There won't be any system level programming. Which data structure in Java would be the most efficient one for the message queue?

  • Request: DATA STRUCTURES files and examples

    please could you provide me some resources Data Structure using Java (NetBeans)..
    I hardly understood our instructor lessons..

    mark2k7 wrote:
    nonsense replies from nonsense people!! WTF!! Indeed. That's what everyone thought reading your question. Perhaps if you put a little more thought into asking specific, coherent questions you would get more useful answers.

  • Tree Data Type for top-down travelling

    I need a tree data structure to represent a category-subcategory. Only algorithm I need is to find all children from a given node. What is the effective constructure of such tree?
    Thanks.

    The only reason they post is they know somebody will
    do their homework for them. The point being, don'tdo
    it for them. The ultimate point being -- you don't
    want to work with someone that got through theircomp
    sci degree by posting to forums (and copying from
    others), but it actually happens. I had a friend in
    college that got his degree this way, and to his
    graduating day -- he couldn't get 3 lines of code to
    coplile (yes, that means ever.)Come on, I don't believe for a minute that you can
    cheat your way to a masters degree by getting "help"
    from forums. And if you can it's the university that's
    to blame.I never said it was a Master in CS.. BS in CS.
    You say you won't do homework for people. Why not? if
    you find a question interesting why not do it and post
    if with a full explanation and full source code. A
    forum is a public environment. What you do here is
    there for everyone to see. By doing this you actually
    help universities stop potential cheating. It's
    somewhat counter-intiutive but this is how it works.Plagiarism is still cheating, and I believe it is taking credit for work you did not do: copying from a forum, public of not, is still cheating. In ancient times (when I was in college) they used to expell you for turning in other people's work (if you were caught).
    Also what do you know about this person you suspect is
    posting homework for the purpose of cheating. Nothing.
    It can be an isolated person who really has no one
    else to ask.In a University, college, or even HS environment there are always other people to ask--and that is how the system there works.
    Also why is helping someone with homework so
    especially awful. I would rather not help someone with
    work related problems. Why should I help someone for
    free to do something they've been hired to do and get
    paid to do?What is the differenct? When you get the degree you are certified by a major institution of learning to know the materials covered in the coursework you completed. Employers used to assume becasue you have a degree you actually knew a little about the subject. Not any more!!! I wish you could see the millions of dollars each year that are wasted screening unqualified people that have degrees and the millions of dollars wasted trying to work with the ones that made it through the interviews because you did assume they knew at least the basics of the course work for the degree. (I speak here from experience.) We have had to make much more rigorous testing for our candidates to screen out the unqualified--basically you have to take an aggregate final to get into the interview process.
    Also I find cheaters who makes it to a job quite
    benign. There are other types I dislike more, like the
    psychopats and the bullies to name a few.If I have 10 workers and 8 of them cheated their way through college and do not have the problem solving, imagination, and skills needed to be productive and I have 2 "bullies" that give me the world on a silver platter when ever I ask them to do something... guess who is going to get the raises and promotions.
    My conclusion is that you should post at forums only
    if it gives YOU something.I support free information, and I share knowlege and ideas freely and try to cultivate an environment that other will do so too. I have to put a limit there when students want HW done--it is their assignment to do it, they are graded not only on correctness, but also on imagination, problem solving. Do it for them and you weaken the system and eventually the industry.
    As I have said in forums before: Cheating at college level and getting your degree when you are unqualified now costs millions in dollars that have to passed on to the general public to maintain normal operation. Does cheating hurt? Believe it or not, it cost you dollars out of your pocket each and every day.

  • Java data structure

    H!!
    I am looking for a good on line tutorial about
    Java Data structure. please help me.
    peter

    Hi again!
    This is my first time that I want to learn
    about : stack, list, linked list, queue, tree..
    . whit Java.Stack, list, linked list, queue and trees are data structures which are the same independent of the programming language. They are more of a concept.
    The best way to find more information is to google on the structure you want more information on. Here's an explanation on how a linked list works:
    http://encyclopedia.lockergnome.com/s/b/Linked_list
    /Kaj

  • Build XML for Custom Nested Accordian (like Tree View Structure) for SharePoint List Data

    Expected output in Xml:
    <?xml version="1.0" encoding="utf-8" ?>
    - <TopRoot>
    - <Root id="1" Name="Department">
    - <Type id="2" Name="IT">
    - <SubType id="3" Name="Technology">
      <SubSubType id="4" Name="Sharepoint" />
      <SubSubType id="5" Name="ASP.NET" />
      <SubSubType id="6" Name="HTML 5" />
      </SubType>
      </Type>
    </Root>
    </TopRoot>
    List Details:
    list details for storing category / sub category data and code to build tree structure for the same.
    1.Create Custom List named “CategoryDetails”:
    2.Create Column “Category Name” of type single line of text. Make it as required field and check Yes for Enforce Unique values.
    3.Create column “Parent Category” of type lookup. under Additional Column Settings.
    Get information dropdown, select “CategoryDetails”.
    4.Choice column ["SRTypeName"] 1.Root,2.SRTYPE,3.SubSRTYPE, 4.SUBSUBSRTYPE
    In this column dropdown, select “Category Name”:  
    Referance:
    http://www.codeproject.com/Tips/627580/Build-Tree-View-Structure-for-SharePoint-List-Data    -fine but don't want tree view just generate xml string
    i just follwed above link it work perferfectly fine for building tree view but i don't want server control.
    Expected Result:
    My ultimate goal is to generate xml string like above format without building tree view.
    I want to generate xml using web service and using xml i could convert into nested Tree View Accordian in html.
    I developed some code but its not working to generate xml /string.
    My modified Code:
    public const string DYNAMIC_CAML_QUERY =
            "<Where><IsNull><FieldRef Name='{0}' /></IsNull></Where>";
            public const string DYNAMIC_CAML_QUERY_GET_CHILD_NODE =
            "<Where><Eq><FieldRef Name='{0}' /><Value Type='LookupMulti'>{1}</Value></Eq></Where>";
            protected void Page_Load(object sender, EventArgs e)
                if (!Page.IsPostBack)
                 string TreeViewStr= BuildTree();
                 Literal1.Text = TreeViewStr;
            StringBuilder sbRoot= new StringBuilder();
            protected string BuildTree()
                SPList TasksList;
                SPQuery objSPQuery;
                StringBuilder Query = new StringBuilder();
                SPListItemCollection objItems;
                string DisplayColumn = string.Empty;
                string Title = string.Empty;
                string[] valueArray = null;
                try
                    using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                        using (SPWeb web = site.OpenWeb())
                            TasksList = SPContext.Current.Web.Lists["Service"];
                            if (TasksList != null)
                                objSPQuery = new SPQuery();
                                Query.Append(String.Format(DYNAMIC_CAML_QUERY, "Parent_x0020_Service_x0020_Id"));
                                objSPQuery.Query = Query.ToString();
                                objItems = TasksList.GetItems(objSPQuery);
                                if (objItems != null && objItems.Count > 0)
                                    foreach (SPListItem objItem in objItems)
                                        DisplayColumn = Convert.ToString(objItem["Title"]);
                                        Title = Convert.ToString(objItem["Title"]);
                                        int rootId=objItem["ID"].ToString();
                                        sbRoot.Append("<Root id="+rootId+"
    Name="+Title+">");
                                        string SRAndSUBSRTpe = CreateTree(Title, valueArray,
    null, DisplayColumn, objItem["ID"].ToString());
                                        sbRoot.Append(SRAndSUBSRTpe);
                                        SRType.Clear();//make SRType Empty
                                        strhtml.Clear();
                                    SRType.Append("</Root>");
                catch (Exception ex)
                    throw ex;
                return SRType.ToString();
             StringBuilder strhtml = new StringBuilder();
            private string CreateTree(string RootNode, string[] valueArray,
          List<SPListItem> objNodeCollection, string DisplayValue, string KeyValue)
                try
                    strhtml.Appends(GetSRType(KeyValue, valueArray, objNodeCollection);
                catch (Exception ex)
                    throw ex;
                return strhtml;
            StringBuilder SRType = new StringBuilder();
            private string GetSRType(string RootNode,
            string[] valueArray, List<SPListItem> objListItemColn)
                SPQuery objSPQuery;
                SPListItemCollection objItems = null;
                List<SPListItem> objNodeListItems = new List<SPListItem>();
                objSPQuery = new SPQuery();
                string objNodeTitle = string.Empty;
                string objLookupColumn = string.Empty;
                StringBuilder Query = new StringBuilder();
                SPList objTaskList;
                SPField spField;
                string objKeyColumn;
                string SrTypeCategory;
                try
                    objTaskList = SPContext.Current.Web.Lists["Service"];
                    objLookupColumn = "Parent_x0020_Service_x0020_Id";//objTreeViewControlField.ParentLookup;
                    Query.Append(String.Format
                    (DYNAMIC_CAML_QUERY_GET_CHILD_NODE, objLookupColumn, RootNode));
                    objSPQuery.Query = Query.ToString();
                    objItems = objTaskList.GetItems(objSPQuery);
                    foreach (SPListItem objItem in objItems)
                        objNodeListItems.Add(objItem);
                    if (objNodeListItems != null && objNodeListItems.Count > 0)
                        foreach (SPListItem objItem in objNodeListItems)
                            RootNode = Convert.ToString(objItem["Title"]);
                            objKeyColumn = Convert.ToString(objItem["ID"]);
                            objNodeTitle = Convert.ToString(objItem["Title"]);
                            SrTypeCategory= Convert.ToString(objItem["SRTypeName"]);
                           if(SrTypeCategory =="SRtYpe")
                              SRType.Append("<Type  id="+objKeyColumn+" Name="+RootNode+ ">");
                             if (!String.IsNullOrEmpty(objNodeTitle))
                              SRType.Append(GetSRType(objKeyColumn, valueArray, objListItemColn));
                          if(SrTypeCategory =="SRSubTYpe")
                              SRType.Append("<SRSubType  id="+objKeyColumn+" Name="+RootNode+
    ">");  
                             if (!String.IsNullOrEmpty(objNodeTitle))
                              SRType.Append(GetSRType(objKeyColumn, valueArray, objListItemColn));
                          if(SrTypeCategory =="SubSubTYpe")
                              SRType.Append("<SubSubType  id="+objKeyColumn+" Name="+RootNode +"
    ></SubSubType");  
                        SRType.Append("</SubType>");
                        SRType.Append("</Type>");
                catch (Exception ex)
                    throw ex;
                return SRType.ToString();
                // Call method again (recursion) to get the child items

    Hi,
    According to your post, my understanding is that you want to custom action for context menu in "Site Content and Structure" in SharePoint 2010.
    In "SiteManager.aspx", SharePoint use MenuItemTemplate class which represent a control that creates an item in a drop-down menu.
    For example, to create or delete the ECB menu for a list item in
    "Site Content and Structure", we can follow the steps below:
    To add the “My Like” menu, we can add the code below:      
    <SharePoint:MenuItemTemplate
    UseShortId=false
    id="OLListItemLike"
    runat="server"
    Text="My Like"
    ImageUrl="/_layouts/images/DelItem.gif"
    ClientOnClickNavigateUrl="https://www.google.com.hk/"
    />
    To remove the “Delete” menu, we can comment the code below:
    <SharePoint:MenuItemTemplate
    UseShortId=false
    id="OLListItemDelete"
    runat="server"
    Text="<%$Resources:cms,SmtDelete%>"
    ImageUrl="/_layouts/images/DelItem.gif"
    ClientOnClickScript="%SmtObjectDeleteScript%"
    />            
    The result is as below:
    More information:
    MenuItemTemplate Class (Microsoft.SharePoint.WebControls)
    MenuItemTemplate.ClientOnClickScript property (Microsoft.SharePoint.WebControls)
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • Is timesten still using T-tree as data structure?

    I just come across this paper - http://www.memdb.com/paper.pdf , this researcher do some experiments and showing that using concurrent B-tree algorithm is actually faster than T-tree operation. How do you think about this paper? Do you think actually he is using a inefficient algorithm to access T-tree? Or, Timesten already know the limitation of T-tree and have changed the internal data-structure?

    Yes, we are aware of the comparisons between T-Trees, concurrent B-trees etc. At the moment TimesTen still uses T-trees but this may change in the future :-)
    Chris

Maybe you are looking for

  • Error while setting data into table

    I am getting an error while inerting a new record into table error is JBO-27010: Attribute set with value 9991431 for AckmntInd in EdMsgHeaderDetailsEO has invalid precision/scale oracle.jbo.AttrSetValException: JBO-27010: Attribute set with value 99

  • Business content Transport error

    Hi , I am not able to transport Business content cubes as its giving error " Start of the after-import method RS_ODSO_AFTER_IMPORT for object type(s) ODSO (Activation Mode) InfoObject 0CREDITOR is not available in version A" although all the objects

  • PhotoShop CS5 upgrade error U44M1I210

    When i tried to upgrade PhotoShop CS5, received this error: Photoshop 12.0.4 update for Photoshop CS5 There was an error installing this update. Please quit and try again later. Error Code: U44M1I210???

  • Best report builder in Java???

    Hi All, Sorry because this question maybe not related to the EJB.But because I know all of u are prof. in java so I asked this question. I am developing applications in java .But I stop when I need to make reports in my applications .So, what is the

  • How to hide SAP logo ?

    Hi , After login in the portal SAP logo comes in heading tab . How to hide that SAP logo?