English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Given n positive integers {d1, d2, ..} st d1+d2+... = 2n-2, does there always exist a tree with n nodes...whose degree are exactly d1, d2, d3, .. dn.

How could I construct such a tree??

2007-03-27 08:16:04 · 1 answers · asked by roberto1502 1 in Computers & Internet Programming & Design

1 answers

ok i dont really understand the Q; u want n integer with the a sum of (2*n-2)?! this means they r all 2's except for two 1's...(that's if understand it correctly...)
anyway, about constructing the tree...
(i'll assume ur using C++)
try making a class with a dynamically allocated array of pointers to this class and one integer to hold the number...
this way each object of this class will be a node in ur class...nodes with zero pointers allocated in their arrays r leaves...u might wanna add a pointer to node before...

i cant go through the whole thing, but this should get u started...

hope i've helped

2007-03-27 08:33:11 · answer #1 · answered by Khaled Z 3 · 0 0

fedest.com, questions and answers