Results 1 to 9 of 9
- 10-07-2011, 07:48 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 5
- Rep Power
- 0
Linked list with multiple links to implement Tree data structure
Hello
I am interested to implement Tree data structure in that i want to dynamically create links if needed. For example i cannot restrict my node to have only two links front and back. If need arises i should be able to add third link dynamically.
How to do this? Kindly help me to get the answer.
kavitha
- 10-07-2011, 07:59 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
Re: Linked list with multiple links to implement Tree data structure
Define 'links'. If I understand correctly, you could use a List of outgoing/child nodes (or edges, depending upon how complex you want the data structure to be) for each Node.
- 10-09-2011, 08:29 AM #3
Member
- Join Date
- Oct 2011
- Posts
- 5
- Rep Power
- 0
Re: Linked list with multiple links to implement Tree data structure
Thank you for your response.
Actually my tree will be having the number of children based upon the users wish. This information is dynamically got from the user if he wishes to add new child at that moment i should be able to do that.
Example : a-b-c-d
is one path and if i want to a child to "b" i should be able to create a new link in b and i should be able to generate another path start from b
Example : "a-b-c-d" is one path and "a-b-e-f " is another path
This is the actual situation for me to implement.
Thank you
- 10-09-2011, 08:55 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
Re: Linked list with multiple links to implement Tree data structure
You can define an arbitrary tree with Nodes having three pointers/links/references:
1) a pointer to the parent Node;
2) a pointer to the next sibling Node;
3) a pointer to its leftmost child Node.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-16-2011, 07:21 PM #5
Member
- Join Date
- Oct 2011
- Posts
- 5
- Rep Power
- 0
Re: Linked list with multiple links to implement Tree data structure
Yes i understood what you have mentioned but my problem is not one sibling it can be multiple siblings and the count also i do not know
Thanks in advance
kavitha
- 10-16-2011, 07:29 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
Re: Linked list with multiple links to implement Tree data structure
You didn't understand my hint; if a (root) node A has three children B, C and D then:
1) A has a null parent node and B, C and D have A as their parent node;
2) A has a null sibling node, B has C as its sibling node, C has D as its sibling node and D has null as its sibling node;
3) A has B as its leftmost child node and the others has null as their leftmost child node.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-16-2011, 07:51 PM #7
Member
- Join Date
- Oct 2011
- Posts
- 5
- Rep Power
- 0
- 10-16-2011, 08:58 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
Re: Linked list with multiple links to implement Tree data structure
Sure, that three pointer structure can be used for any tree; the advantage of that structure is that there are just a fixed number of pointers per node; the disadvantage is that you have to traverse the sibling list if you want to find a (any) sibling.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-17-2011, 09:17 AM #9
Member
- Join Date
- Oct 2011
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Tree data structure
By Nacao in forum New To JavaReplies: 18Last Post: 08-23-2011, 06:26 PM -
Spreadsheet data - linked list or hashmap
By j919 in forum New To JavaReplies: 2Last Post: 02-19-2011, 07:20 PM -
data structure with multiple keys
By jon80 in forum New To JavaReplies: 2Last Post: 06-13-2009, 03:02 PM -
Requesting some tips to implement an interface between a tree structure and table
By Karanam in forum AWT / SwingReplies: 1Last Post: 10-20-2008, 12:58 PM -
Doubly-linked list with data structure
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 10:30 PM


LinkBack URL
About LinkBacks
Reply With Quote


Bookmarks