algorithm - Is it possible to design a tree where nodes have infinitely many children? -
how can design tree lots (infinite number) of branches ?
which data structure should use store child nodes ?
you can't store infinitely many children, since won't fit memory. however, can store unboundedly many children - is, can make trees each node can have number of children no fixed upper bound.
there few standard ways this. have each tree node store list of of children (perhaps dynamic array or linked list), done tries. example, in c++, might have this:
struct node { /* ... data node goes here ... */ std::vector<node*> children; };
alternatively, use left-child/right-sibling representation, represents multiway tree binary tree. used in priority queues binomial heaps. example:
struct node { /* ... data node ... */ node* firstchild; node* nextsibling; };
hope helps!
Comments
Post a Comment