Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Non-Binary Trees

Reply
Thread Tools

Non-Binary Trees

 
 
Will Oram
Guest
Posts: n/a
 
      10-27-2003
Hi,

My assignment is to create a non-binary tree of arbitrary form, and then
print out the data in an orderly fashion. The handout contains a tree to
be inputted:

2
/ | \
3 7 5
/ \ |
1 8 6

If that 7 weren't there, it would be a binary tree and I could deal with
it easily. I've searched through texts and notes and the Internet but
couldn't find any documentation on the subject.

What's the best way to deal with this situation?

Thanks.
 
Reply With Quote
 
 
 
 
Howard
Guest
Posts: n/a
 
      10-27-2003

"Will Oram" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> My assignment is to create a non-binary tree of arbitrary form, and then
> print out the data in an orderly fashion. The handout contains a tree to
> be inputted:
>
> 2
> / | \
> 3 7 5
> / \ |
> 1 8 6
>
> If that 7 weren't there, it would be a binary tree and I could deal with
> it easily. I've searched through texts and notes and the Internet but
> couldn't find any documentation on the subject.
>
> What's the best way to deal with this situation?
>
> Thanks.


So what's the problem exactly? Instead of having a left and right child,
have an array (or vector) of children. Have you done any programming at all
for this yet? Try taking the code for a binary-tree and modifying it like I
suggested. Then, if you have an actual C++ problem, come back for more
specific help.

-Howard




 
Reply With Quote
 
 
 
 
Ivan Vecerina
Guest
Posts: n/a
 
      10-27-2003
"Will Oram" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
| My assignment is to create a non-binary tree of arbitrary form, and then
| print out the data in an orderly fashion. The handout contains a tree to
| be inputted:
|
| 2
| / | \
| 3 7 5
| / \ |
| 1 8 6
|
| If that 7 weren't there, it would be a binary tree and I could deal with
| it easily. I've searched through texts and notes and the Internet but
| couldn't find any documentation on the subject.

Wrong NG, e.g. comp.pogramming would be more adequate.
This said...

| What's the best way to deal with this situation?

Every tree can be represented as a binary tree, where:
- the left node points to the first sibling
- the right node points to the next brother

i.e. with left links as | and right links as -- ,
the following is a binary tree representation of
the tree you described above:

2
|
3--7--5
| |
1--8 6

You could use this representation to solve your problem.
Alternatively, you can let each not store a dynamically
sized list of its siblings (e.g. using std::vector<>),
or use another representation of a graph or tree (such
as a matrix of booleans).

The right solution probably depends on what you
are / have been studying in class recently.

Recommended reading: Knuth's TAOCP


Regards,
Ivan


 
Reply With Quote
 
Stewart Gordon
Guest
Posts: n/a
 
      10-28-2003


While it was 27/10/03 6:18 pm throughout the UK, Will Oram sprinkled
little black dots on a white screen, and they fell thus:

> Hi,
>
> My assignment is to create a non-binary tree of arbitrary form, and then
> print out the data in an orderly fashion. The handout contains a tree to
> be inputted:

<snip>
> If that 7 weren't there, it would be a binary tree and I could deal with
> it easily. I've searched through texts and notes and the Internet but
> couldn't find any documentation on the subject.


What are you having trouble with, exactly? The data structure, or the
orderly fashion? If the latter, we'll need to know what the orderly
fashion is supposed to look like.

Stewart.

--
My e-mail is valid but not my primary mailbox. Please keep replies on
on the 'group where everyone may benefit.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Binary search trees (AVL trees) jacob navia C Programming 34 01-08-2010 07:27 PM
B+-trees Rico Java 10 08-02-2004 03:32 PM
Trees in the Java Collections framework Joona I Palaste Java 5 06-09-2004 10:42 AM
Binary Trees jova Java 11 04-26-2004 06:41 AM
Trees in java Pif Java 1 04-06-2004 11:48 AM



Advertisments