Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 20th, 2006, 2:54 AM   #1
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 155
Rep Power: 3 programmingnoob is on a distinguished road
trees

how many types of trees are there in c++? maybe one of the types would be binary tree, and then there might be subtypes ...

but basically how many types of trees are there in c++?
programmingnoob is offline   Reply With Quote
Old Jul 20th, 2006, 2:57 AM   #2
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
I wasn't aware of there being different types of tree. A binary tree is a special case, of course, but it's still just a regular ol' tree. That's like saying "How many types of rectangles are there? Maybe one of the types would be squares..."
__________________
Few people deserve to be compared to (Rush) Limbaugh, most of them were convicted at the Nuremburg trials.
--WilliamSChips on Slashdot
uman is offline   Reply With Quote
Old Jul 20th, 2006, 3:00 AM   #3
Twilight
Programmer
 
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3 Twilight is on a distinguished road
The special ones I can think of offhand are Binary Trees and Balanced Trees, but there really are about as many tree types as you count.
Twilight is offline   Reply With Quote
Old Jul 20th, 2006, 3:04 AM   #4
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: WA, USA
Posts: 343
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
why would some trees be specific to C++? i thought the idea was some what universal in computers science
__________________
i dont know much about programming but i try to help
mrynit is offline   Reply With Quote
Old Jul 20th, 2006, 3:17 AM   #5
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3 Jimbo is on a distinguished road
Go here and search for tree (and see all the different names for similar or identical structures :o). And as mrynit mentioned, trees aren't specific to C++
Jimbo is offline   Reply With Quote
Old Jul 20th, 2006, 3:23 AM   #6
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 155
Rep Power: 3 programmingnoob is on a distinguished road
well .... i am a little confused ....

do binary trees have to store numbers in their nodes? if yes, then how do i build an abstract syntax tree for my parser?

i was also thinking about expression trees? ....
programmingnoob is offline   Reply With Quote
Old Jul 20th, 2006, 3:36 AM   #7
lectricpharaoh
SEXY SHOELESS GOD OF WAR!
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,197
Rep Power: 5 lectricpharaoh will become famous soon enough
Heap data structures are often (always?) implemented as a form of tree, too.

As for their being more types than binary, it's perfectly possible to have a hypothetical tree where each node had more than two potential child nodes. I can't see it offering any advantage except in very specific circumstances, like perhaps a radix sort, but then there are probably better structures for those purposes (hybrid hash table, for example).
Quote:
Originally Posted by programmingnoob
well .... i am a little confused ....

do binary trees have to store numbers in their nodes? if yes, then how do i build an abstract syntax tree for my parser?

i was also thinking about expression trees? ....
Trees can store whatever you want in their nodes. Think of each node in a binary tree as an object (in the generic sense, not necessarily an instance of a class) wrapped up with a couple of pointers to the child nodes. Each pointer will be either a valid pointer to a node, or NULL. If that was all it was, it wouldn't be too useful, but when you add some methods to control how nodes are added and removed, it can be very useful.

Two common variants are the binary search tree and the heap. In the former, nodes are added/removed in such a manner that the child node that is 'less than' a parent node is on one branch, and the child node that is 'greater than' the parent is on the other branch. This is done in recursive fashion (so a child on a 'less than' node is less than its parent, and the parent's parent, and so on), and because the nodes are objects, the programmer defines the semantics of less than/greater than. This form of a tree is intended to gain the benefits of a linked list without the heavy performance penalties of arbitrary additions to the list. In the latter, the nodes are added/removed in such a way that the 'largest' (or smallest) is always on top. Again, what defines 'largest' is up to the programmer. This type of tree is often used for priority queues (where the item with highest importance gets processed first).
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick

Last edited by lectricpharaoh; Jul 20th, 2006 at 3:51 AM.
lectricpharaoh is offline   Reply With Quote
Old Jul 20th, 2006, 3:40 AM   #8
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 155
Rep Power: 3 programmingnoob is on a distinguished road
Quote:
Originally Posted by lectricpharaoh
Heap data structures are often (always?) implemented as a form of tree, too.

As for their being more types than binary, it's perfectly possible to have a hypothetical tree where each node had more than two potential child nodes. I can't see it offering any advantage except in very specific circumstances, like perhaps a radix sort, but then there are probably better structures for those purposes (hybrid hash table, for example).
what kind of data strcuture would you recommend for an abtsract syntax tree for my parser?
programmingnoob is offline   Reply With Quote
Old Jul 20th, 2006, 3:54 AM   #9
lectricpharaoh
SEXY SHOELESS GOD OF WAR!
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,197
Rep Power: 5 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by programmingnoob
what kind of data strcuture would you recommend for an abtsract syntax tree for my parser?
Dunno. I haven't done much work with parsing, and it depends a lot on what you want to do. What do you need a parser for? More information makes us more likely to be able to help.

Also, reread my post above. I started editing it in between when I first posted it, and when you read/replied to it, and added some more info.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Jul 20th, 2006, 3:58 AM   #10
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
Um, I am actually in the middle of writing a program that revolves around a tree that is not binary.
__________________
Few people deserve to be compared to (Rush) Limbaugh, most of them were convicted at the Nuremburg trials.
--WilliamSChips on Slashdot
uman is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning an array of lists deanosrs C 42 Apr 13th, 2006 2:35 PM
Moving directory trees via .bat files Mansooj Bash / Shell Scripting 11 Jan 17th, 2006 3:45 AM
Flattening Trees Into Arrays Will Piovano C 2 Nov 11th, 2005 9:00 AM
Trees & Checkboxes quants Delphi 0 Apr 18th, 2005 11:18 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:02 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC