473,394 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Non-Binary Trees

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.
Jul 19 '05 #1
3 6701

"Will Oram" <sp*****@ihatespammers.com> wrote in message
news:20********************@news.cwru.edu...
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


Jul 19 '05 #2
"Will Oram" <sp*****@ihatespammers.com> wrote in message
news:20********************@news.cwru.edu...
| 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
Jul 19 '05 #3


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.
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
14
by: Patrick Kowalzick | last post by:
Dear all, I have an existing piece of code with a struct with some PODs. struct A { int x; int y; };
2
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my...
0
by: amitvps | last post by:
Secure Socket Layer is very important and useful for any web application but it brings some problems too with itself. Handling navigation between secure and non-secure pages is one of the cumbersome...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
12
by: puzzlecracker | last post by:
is it even possible or/and there is a better alternative to accept input in a nonblocking manner?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.