Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 3.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-23-2004, 09:16 PM   PM User | #1
kee
New to the CF scene

 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
kee is an unknown quantity at this point
where can I find the example of Tree structure using JAVA ?

where can I find the example of Tree structure using JAVA ? I would like to do a family tree by using Java. but I have no idea.

Thank you
Kee
kee is offline   Reply With Quote
Old 08-23-2004, 10:18 PM   PM User | #2
Jason
Regular Coder

 
Join Date: Feb 2003
Location: California
Posts: 925
Thanks: 0
Thanked 0 Times in 0 Posts
Jason is an unknown quantity at this point
a tree in java is also known as a linked list. There are different traversals of a tree but thats more deeper than your looking I think. Google for linked list and you should get what your looking for.


Jason
Jason is offline   Reply With Quote
Old 08-24-2004, 12:22 AM   PM User | #3
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
Quote:
Originally Posted by Jason
a tree in java is also known as a linked list. There are different traversals of a tree but thats more deeper than your looking I think. Google for linked list and you should get what your looking for.


Jason
Actually no a tree in java is not also known as a linked list. A linked list is an entirely different data structure. A linked list is a sequence of interconnected nodes. A linked list is a linear structure, a tree is non-linear.
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 08-24-2004, 12:45 AM   PM User | #4
Jason
Regular Coder

 
Join Date: Feb 2003
Location: California
Posts: 925
Thanks: 0
Thanked 0 Times in 0 Posts
Jason is an unknown quantity at this point
actually a node in a linked list depending on how you write the code can have two children using 2 different pointers while another pointer points to the parent giving the illusion of a tree. Thats how I wrote all my trees in java


Jason
Jason is offline   Reply With Quote
Old 08-24-2004, 12:51 AM   PM User | #5
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
Quote:
Originally Posted by Jason
actually a node in a linked list depending on how you write the code can have two children using 2 different pointers while another pointer points to the parent giving the illusion of a tree. Thats how I wrote all my trees in java


Jason
After suffering through a semester of a data structures course in java in college I have to disagree with you there.

A tree is not a linked list or vice versa.
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 08-24-2004, 12:57 AM   PM User | #6
Jason
Regular Coder

 
Join Date: Feb 2003
Location: California
Posts: 925
Thanks: 0
Thanked 0 Times in 0 Posts
Jason is an unknown quantity at this point
only 1, I had to do more than just 1 sem on data structures back in college and here is a better description of trees and linked lists...

http://www.cs.utexas.edu/users/oursland/tree/

you may have used a btree class or something but I had to write the whole thing.



Jason
Jason is offline   Reply With Quote
Old 08-24-2004, 07:36 AM   PM User | #7
sad69
Senior Coder

 
Join Date: Feb 2004
Posts: 1,206
Thanks: 0
Thanked 0 Times in 0 Posts
sad69 is an unknown quantity at this point
A tree is not a linked list. A tree (be it binary, or n-ary..) can be implemented using linked nodes, similar to a linked-list; or using an array and indices to reference the children and parent (i/2=parent, 2i=left_child, 2i+1=right_child, I think..), and there are other ways still.

The term Tree refers to the idea of a tree structure, independent of implementation. The term Linked-List (they can be singly or doubly-linked) refers specifically to the notion of nodes being linked to one another to give a linear list of nodes.

If a binary tree is implemented as linked nodes, then it is somewhat similar to the implementation of a doubly-linked list. A linked-list in this case is almost identical to a binary tree where each node only has left children. However, once that tree acquires a right child, it is no longer a linked list (as long as the right child is not the node's parent! But then, it wouldn't be a tree any longer, but a graph with cycles..).

Sorry to elaborate, but that was a nice refresher in my mind as well!

Sadiq.
sad69 is offline   Reply With Quote
Old 08-24-2004, 09:40 PM   PM User | #8
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
Quote:
Originally Posted by sad69
A tree is not a linked list. A tree (be it binary, or n-ary..) can be implemented using linked nodes, similar to a linked-list; or using an array and indices to reference the children and parent (i/2=parent, 2i=left_child, 2i+1=right_child, I think..), and there are other ways still.

The term Tree refers to the idea of a tree structure, independent of implementation. The term Linked-List (they can be singly or doubly-linked) refers specifically to the notion of nodes being linked to one another to give a linear list of nodes.

If a binary tree is implemented as linked nodes, then it is somewhat similar to the implementation of a doubly-linked list. A linked-list in this case is almost identical to a binary tree where each node only has left children. However, once that tree acquires a right child, it is no longer a linked list (as long as the right child is not the node's parent! But then, it wouldn't be a tree any longer, but a graph with cycles..).

Sorry to elaborate, but that was a nice refresher in my mind as well!

Sadiq.

Thank your for elaborating my point. I didn't feel like arguing. I had to go through all of that during my data structures and discrete structures courses in college and didn't feel like going back and digging up the details. We went into great depth on the subject but that was years ago and I was pretty sure my memory of it was correct.
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:42 AM.


Advertisement
Log in to turn off these ads.