Click to See Complete Forum and Search --> : 1 parent node and multiple child nodes


Sriya
January 6th, 2007, 06:53 AM
Hi all...

In a binary tree.. we have one parent node and two Child node, right child and the left child. Do we have a possibility for a datastucture that has one parent node and variable number of child nodes, instead of just two as in case of a binary tree??

Simple put... is it possible to have a Tree-like structure with one Parent node and 'n' child nodes??

Pls help me in this.

Thank you all!!

Sriya!

Zachm
January 6th, 2007, 11:39 AM
Of course it is possible !
For example, a node structure may look like this:

struct node
{
node *children;
int numOfCildren;
node * parent;
data *d;
}


Where 'children' is an array of child nodes.
Note that several tree operations must be changed to manage this kind of tree, for example element insertion & deletion operations.
Does the tree needs to be a balanced tree ? if so, see the following link on B / B+ trees:
http://en.wikipedia.org/wiki/B-tree

Good luck !

yiannakop
January 9th, 2007, 05:53 AM
Hi. Nice explaination Zachm. Sriya, this (http://www.amazon.com/Data-Structures-Algorithm-Analysis-2nd/dp/0201498405) book contains some c code for a number of data structures. You can also find some free code from this book here (http://www.cs.fiu.edu/~weiss/dsaa_c2e/files.html) . Also, C: How to program (Deitel & Deitel), which is generally a good book for C programming, if I remember right, has a couple of sections for data structures (including trees and lists) using C. Also, this (http://www.brpreiss.com/books/opus4/html/book.html) is a rather good online book.